<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="http://macournoyer.com/feed.xml" rel="self" type="application/atom+xml" /><link href="http://macournoyer.com/" rel="alternate" type="text/html" /><updated>2025-07-17T13:39:03+00:00</updated><id>http://macournoyer.com/feed.xml</id><title type="html">Marc-André Cournoyer</title><subtitle>Code, lifting &amp; loops</subtitle><entry><title type="html">Rust</title><link href="http://macournoyer.com/blog/2019/03/19/rust/" rel="alternate" type="text/html" title="Rust" /><published>2019-03-19T00:00:00+00:00</published><updated>2019-03-19T00:00:00+00:00</updated><id>http://macournoyer.com/blog/2019/03/19/rust</id><content type="html" xml:base="http://macournoyer.com/blog/2019/03/19/rust/"><![CDATA[<p>I must admit, the first few times I saw some <a href="https://www.rust-lang.org/">Rust</a> code I thought it was too complex, that the learning curve, versus the rewards it claimed, was too high. I thought it would never pick up and become a popular programming language.</p>

<div class="language-rust highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">// A simple Ruzzle solver in Rust.</span>
<span class="c1">// Finds all the word combinations in a 4x4 grid of letters. Some parts omitted.</span>
<span class="c1">// Source: https://gist.github.com/macournoyer/c891d3a9233c18778252c8a367ee68c6</span>

<span class="k">struct</span> <span class="n">Board</span> <span class="p">{</span>
    <span class="n">dictionary</span><span class="p">:</span> <span class="n">HashSet</span><span class="o">&lt;</span><span class="nb">String</span><span class="o">&gt;</span><span class="p">,</span>
    <span class="n">letters</span><span class="p">:</span> <span class="nb">String</span><span class="p">,</span>
<span class="p">}</span>

<span class="k">impl</span> <span class="n">Board</span> <span class="p">{</span>
    <span class="k">pub</span> <span class="k">fn</span> <span class="nf">letter_at</span><span class="p">(</span><span class="o">&amp;</span><span class="k">self</span><span class="p">,</span> <span class="n">i</span><span class="p">:</span> <span class="nb">usize</span><span class="p">)</span> <span class="k">-&gt;</span> <span class="nb">String</span> <span class="p">{</span>
        <span class="k">self</span><span class="py">.letters</span><span class="nf">.chars</span><span class="p">()</span><span class="nf">.nth</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="nf">.unwrap</span><span class="p">()</span><span class="nf">.to_string</span><span class="p">()</span>
    <span class="p">}</span>

    <span class="k">pub</span> <span class="k">fn</span> <span class="nf">find_words</span><span class="p">(</span><span class="o">&amp;</span><span class="k">self</span><span class="p">)</span> <span class="k">-&gt;</span> <span class="n">HashSet</span><span class="o">&lt;</span><span class="nb">String</span><span class="o">&gt;</span> <span class="p">{</span>
        <span class="k">let</span> <span class="k">mut</span> <span class="n">found</span> <span class="o">=</span> <span class="nn">HashSet</span><span class="p">::</span><span class="nf">new</span><span class="p">();</span>
        <span class="k">for</span> <span class="n">i</span> <span class="k">in</span> <span class="mi">0</span><span class="o">..</span><span class="mi">16</span> <span class="p">{</span>
            <span class="n">found</span><span class="nf">.extend</span><span class="p">(</span><span class="k">self</span><span class="nf">.find_from_letter</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="k">self</span><span class="nf">.letter_at</span><span class="p">(</span><span class="n">i</span><span class="p">),</span> <span class="nd">vec!</span><span class="p">[</span><span class="n">i</span><span class="p">]));</span>
        <span class="p">}</span>
        <span class="n">found</span>
    <span class="p">}</span>

    <span class="k">pub</span> <span class="k">fn</span> <span class="nf">find_from_letter</span><span class="p">(</span><span class="o">&amp;</span><span class="k">self</span><span class="p">,</span> <span class="n">i</span><span class="p">:</span> <span class="nb">usize</span><span class="p">,</span> <span class="n">word</span><span class="p">:</span> <span class="nb">String</span><span class="p">,</span> <span class="k">mut</span> <span class="n">visited</span><span class="p">:</span> <span class="nb">Vec</span><span class="o">&lt;</span><span class="nb">usize</span><span class="o">&gt;</span><span class="p">)</span> <span class="k">-&gt;</span> <span class="n">HashSet</span><span class="o">&lt;</span><span class="nb">String</span><span class="o">&gt;</span> <span class="p">{</span>
        <span class="k">let</span> <span class="k">mut</span> <span class="n">found</span> <span class="o">=</span> <span class="nn">HashSet</span><span class="p">::</span><span class="nf">new</span><span class="p">();</span>

        <span class="c1">// Find all the possible letter combinations from the current position</span>
        <span class="k">for</span> <span class="n">m</span> <span class="k">in</span> <span class="o">&amp;</span><span class="n">MOVES</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="p">{</span>
            <span class="k">if</span> <span class="o">*</span><span class="n">m</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">{</span> <span class="k">continue</span><span class="p">;</span> <span class="p">}</span>
            <span class="k">let</span> <span class="n">new_i</span> <span class="o">=</span> <span class="p">(</span><span class="n">i</span> <span class="k">as</span> <span class="nb">isize</span> <span class="o">+</span> <span class="n">m</span><span class="p">)</span> <span class="k">as</span> <span class="nb">usize</span><span class="p">;</span>
            <span class="k">if</span> <span class="n">visited</span><span class="nf">.contains</span><span class="p">(</span><span class="o">&amp;</span><span class="n">new_i</span><span class="p">)</span> <span class="p">{</span> <span class="k">continue</span><span class="p">;</span> <span class="p">}</span>
            <span class="n">visited</span><span class="nf">.push</span><span class="p">(</span><span class="n">new_i</span><span class="p">);</span>
            <span class="k">let</span> <span class="n">word</span> <span class="o">=</span> <span class="nd">format!</span><span class="p">(</span><span class="s">"{}{}"</span><span class="p">,</span> <span class="n">word</span><span class="p">,</span> <span class="k">self</span><span class="nf">.letter_at</span><span class="p">(</span><span class="n">new_i</span><span class="p">));</span>
            <span class="c1">// Only words in the dictionary are valid</span>
            <span class="k">if</span> <span class="n">word</span><span class="nf">.len</span><span class="p">()</span> <span class="o">&gt;=</span> <span class="n">MIN_WORD_SIZE</span> <span class="o">&amp;&amp;</span> <span class="k">self</span><span class="py">.dictionary</span><span class="nf">.contains</span><span class="p">(</span><span class="o">&amp;</span><span class="n">word</span><span class="p">)</span> <span class="p">{</span>
                <span class="n">found</span><span class="nf">.insert</span><span class="p">(</span><span class="n">word</span><span class="nf">.clone</span><span class="p">());</span>
            <span class="p">}</span>
            <span class="k">if</span> <span class="n">word</span><span class="nf">.len</span><span class="p">()</span> <span class="o">&lt;=</span> <span class="n">MAX_WORD_SIZE</span> <span class="p">{</span>
                <span class="n">found</span><span class="nf">.extend</span><span class="p">(</span><span class="k">self</span><span class="nf">.find_from_letter</span><span class="p">(</span><span class="n">new_i</span><span class="p">,</span> <span class="n">word</span><span class="nf">.clone</span><span class="p">(),</span> <span class="n">visited</span><span class="nf">.clone</span><span class="p">()));</span>
            <span class="p">}</span>
        <span class="p">}</span>

        <span class="n">found</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
    <span class="nd">println!</span><span class="p">(</span><span class="s">"Loading dictionary ..."</span><span class="p">);</span>
    <span class="k">let</span> <span class="n">dictionary</span> <span class="o">=</span> <span class="nf">load_dict</span><span class="p">(</span><span class="s">"words.txt"</span><span class="p">);</span>
    <span class="nd">println!</span><span class="p">(</span><span class="s">"{} words loaded"</span><span class="p">,</span> <span class="n">dictionary</span><span class="nf">.len</span><span class="p">());</span>

    <span class="k">let</span> <span class="k">mut</span> <span class="n">letters</span> <span class="o">=</span> <span class="nn">String</span><span class="p">::</span><span class="nf">new</span><span class="p">();</span>
    <span class="nd">println!</span><span class="p">(</span><span class="s">"Enter 16 letters: "</span><span class="p">);</span>
    <span class="nn">io</span><span class="p">::</span><span class="nf">stdin</span><span class="p">()</span><span class="nf">.read_to_string</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span> <span class="n">letters</span><span class="p">)</span><span class="nf">.unwrap</span><span class="p">();</span>
    <span class="n">letters</span><span class="nf">.pop</span><span class="p">();</span> <span class="c1">// Remove \n</span>

    <span class="k">let</span> <span class="n">board</span> <span class="o">=</span> <span class="n">Board</span> <span class="p">{</span> <span class="n">dictionary</span><span class="p">,</span> <span class="n">letters</span> <span class="p">};</span>

    <span class="nd">println!</span><span class="p">(</span><span class="s">"Found words: {:?}"</span><span class="p">,</span> <span class="n">board</span><span class="nf">.find_words</span><span class="p">());</span>
<span class="p">}</span>
</code></pre></div></div>

<p>For the past three years, I’ve been using <a href="https://www.rust-lang.org/">Rust</a> almost daily. It started pretty rough. It takes a while to get over the dense syntax. But eventually, I realized that it is so, because a lot needs to be expressed in as few lines as possible.</p>

<p>After using it for a while I realized, Rust is rough, Rust has no mercy, Rust tells you like it is: you’ve been doing some stuff all wrong for quite some time now. And, this hurts quite a bit at first. You’ll feel like: “hey! let me do it my way”. But no. Rust won’t let you, and rightfully so.</p>

<h4 id="ownership">Ownership</h4>

<p>The first thing I realized is that Rust is very annoying when trying to share stuff.</p>

<p>Imagine you want to create a logger and just pass it around to objects you create so they can use it. You know the logger will exist for the entire duration of the program.</p>

<div class="language-rust highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">let</span> <span class="n">logger</span> <span class="o">=</span> <span class="nn">Logger</span><span class="p">::</span><span class="nf">new</span><span class="p">();</span>

<span class="k">let</span> <span class="n">muffin</span> <span class="o">=</span> <span class="nn">Muffin</span><span class="p">::</span><span class="nf">new</span><span class="p">(</span><span class="n">logger</span><span class="p">);</span>
<span class="k">let</span> <span class="n">coffee</span> <span class="o">=</span> <span class="nn">Coffee</span><span class="p">::</span><span class="nf">new</span><span class="p">(</span><span class="n">logger</span><span class="p">);</span> <span class="c1">// &lt;= NO! Can't do that!</span>
</code></pre></div></div>

<p>But Rust says NO! You have “moved” <code class="language-plaintext highlighter-rouge">logger</code> to the <code class="language-plaintext highlighter-rouge">Muffin::new</code> method, it is gone inside that method. So Rust forces you to think: do you want to share it for a brief moment? Then borrow it: <code class="language-plaintext highlighter-rouge">&amp;logger</code>. Share it for a bit longer? <code class="language-plaintext highlighter-rouge">Rc::new(logger)</code>. Share it across threads? <code class="language-plaintext highlighter-rouge">Arc::new(logger)</code>. Allow modifications? <code class="language-plaintext highlighter-rouge">RefCell</code> / <code class="language-plaintext highlighter-rouge">Mutex</code> / <code class="language-plaintext highlighter-rouge">RwLock</code>, etc. You see the picture. Lots of options. Lots of tiny decisions early on. It can make your head dizzy.</p>

<p>It would be easy in this case to say: “I don’t care! I know <code class="language-plaintext highlighter-rouge">logger</code> will exist for the whole duration of the program. I know it will no be modified.” The thing is, you know it now, but us humans, we forget. And that’s how you end up at 2 AM on a weekend debugging a piece-of-shit-code, yours.</p>

<p>Rust is your friend. It tells you the hard truth: “Hey dumbass, don’t do this! You’ll regret it, at 2AM, on a weekend”. It hurts your feelings at first, but you learn to trust and accept it.</p>

<p>This unpleasant part of learning Rust is often what people call “fighting the borrow checker”.</p>

<h4 id="no-null-pointers">No NULL pointers</h4>

<blockquote>
  <p>I call it my billion-dollar mistake. It was the invention of the null reference […] <em>– <a href="https://en.wikipedia.org/wiki/Tony_Hoare#Apologies_and_retractions">Tony Hoare</a></em></p>
</blockquote>

<p>There is no <code class="language-plaintext highlighter-rouge">NULL</code>, <code class="language-plaintext highlighter-rouge">null</code>, <code class="language-plaintext highlighter-rouge">nil</code> in Rust. At least, not unless you play with the unsafe parts.</p>

<div class="language-rust highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">// If a variable can be empty, you must wrap it in an Option (Some or None).</span>
<span class="k">let</span> <span class="k">mut</span> <span class="n">maybe_muffin</span> <span class="o">=</span> <span class="nf">Some</span><span class="p">(</span><span class="n">muffin</span><span class="p">);</span>

<span class="c1">// No more muffin for you</span>
<span class="n">maybe_muffin</span> <span class="o">=</span> <span class="nb">None</span><span class="p">;</span>
</code></pre></div></div>

<p>This even led me to start using <a href="https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html">Optional</a> in Java. But to get the full benefits, you need to have the whole thing (runtime, libraries) not use <code class="language-plaintext highlighter-rouge">null</code>, which Rust has.</p>

<p>By consequence, it’s impossible<sup id="fnref:1" role="doc-noteref"><a href="#fn:1" class="footnote" rel="footnote">1</a></sup> to create a null pointer in your Rust code. One problem less to worry about!</p>

<h4 id="thread-safe-guaranteed">Thread-safe guaranteed!</h4>

<p>Some of the most difficult to track bugs are those around threads. It’s difficult share stuff efficiently when dealing with thread. And quite often, we “forget” to make our code thread-safe.</p>

<p>But Rust, do not allow to write non-thread-safe code by default. “What?” you say. “That must be very verbose, cumbersome, stupid, that I need to make all my code thread-safe”.</p>

<p>No, you only need to make the code you run in threads thread-safe. But even better, the Rust compiler will check for you if you code is already thread-safe and not bother you if there are no issues.</p>

<p>This is achieved in Rust with the <a href="">Sync</a> and <a href="">Send</a> traits<sup id="fnref:2" role="doc-noteref"><a href="#fn:2" class="footnote" rel="footnote">2</a></sup>.</p>

<p>Once again, Rust makes it impossible<sup id="fnref:1:1" role="doc-noteref"><a href="#fn:1" class="footnote" rel="footnote">1</a></sup> to create non-thread-safe code.</p>

<p>How awesome is that?</p>

<h4 id="congrats-to-the-rust-team">Congrats to the Rust team!</h4>

<p>It is difficult to make a brand new language. But what is incredibly more difficult, is building stable, complete and pleasant runtime libraries. The amount of work the Rust team has and is putting into making everything better on a daily basis makes it a very exciting environment to use.</p>

<div class="footnotes" role="doc-endnotes">
  <ol>
    <li id="fn:1" role="doc-endnote">
      <p>“impossible” as in “difficult”. If you really want to do something that Rust doesn’t consider safe, you simply wrap your code in an <code class="language-plaintext highlighter-rouge">unsafe</code> block. <a href="#fnref:1" class="reversefootnote" role="doc-backlink">&#8617;</a> <a href="#fnref:1:1" class="reversefootnote" role="doc-backlink">&#8617;<sup>2</sup></a></p>
    </li>
    <li id="fn:2" role="doc-endnote">
      <p>Traits are kind-of-like interfaces in Java or Go. They contain declarations, but no implementations, although they can provide a default one. Some traits contain no declarations, and are used a markers, eg.: this value can be sent across threads. <a href="#fnref:2" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
  </ol>
</div>]]></content><author><name></name></author><summary type="html"><![CDATA[I must admit, the first few times I saw some Rust code I thought it was too complex, that the learning curve, versus the rewards it claimed, was too high. I thought it would never pick up and become a popular programming language.]]></summary></entry><entry><title type="html">Strength Training</title><link href="http://macournoyer.com/blog/2013/08/22/strength/" rel="alternate" type="text/html" title="Strength Training" /><published>2013-08-22T00:00:00+00:00</published><updated>2013-08-22T00:00:00+00:00</updated><id>http://macournoyer.com/blog/2013/08/22/strength</id><content type="html" xml:base="http://macournoyer.com/blog/2013/08/22/strength/"><![CDATA[<p>So you’re sitting at a computer all day packing on the pounds? Thinking about signing up to the gym to keep in shape? But hey! Most of us have been there. Sign-up for a few months and give up after a few weeks right? I’ve been there many times. But for the last two years and a half I did manage to keep in good shape by going to the gym. So I would like to share with you what worked for me.</p>

<p>First a quick recap (and bragging) of the progress I’ve made. Three years ago I could barely run around the block without thinking I was going to die. Now I can run 5 km three times a week pushing a stroller with my two kids in it. I was also very weak. Here’s the progress I’ve made with my strength over the last three years.</p>

<ul>
  <li>Bench press: 160 pounds to 275 pounds</li>
  <li>Squat: 225 pounds to 360 pounds</li>
  <li>Deadlift: 185 pounds to 405 pounds</li>
</ul>

<h4 id="getting-in-shape">Getting in shape</h4>

<p>Training “to get in shape” never worked for me. You pump irons looking at yourself in the mirror and thinking you’ll look like Arnie in just a few months. But that never works. For two simple reasons.</p>

<p>No measurable goals and no lasting motivation. Looking better, being in better shape, that doesn’t work. Losing weight is easily trackable. But… “losing” is incredibly boring and depressing. How about <em>gaining</em>!</p>

<p>Gaining some strength! (And muscles too.)</p>

<p>Strength training is the perfect type of training for “office” workers like most of us.</p>
<ul>
  <li>It is intense without being mentally draining.</li>
  <li>You can be done in an hour or so.</li>
  <li>It’s the best way to wake up and get you pumped for the day.</li>
  <li>It is easily trackable.</li>
  <li>You can set achievable goals.</li>
  <li>You’ll progress very fast at the beginning, this likely stay motivated.</li>
  <li>The path to your goals is pretty straight forward.</li>
  <li>The first time you lift more than 300 pounds, you’ll feel like a superhero. And that feeling keeps coming back each time you break a new personal record.</li>
  <li>Strength training pushes you to be consistent. If you miss a workout, you’ll never break that record of yours this week!</li>
</ul>

<h4 id="pick-a-simple-program">Pick a simple program</h4>

<p>The simpler the better. I recommend <a href="http://startingstrength.wikia.com/wiki/FAQ:Introduction">Starting Strength</a>, also check out the <a href="http://www.amazon.com/Starting-Strength-3rd-Mark-Rippetoe/dp/0982522738">book</a>.</p>

<p>The nice thing about a program like this one is that you’ll actually know what you’re doing! The worst thing to do in the gym is to improvise. Starting Strength will make you master the barbell and a few very important movements you use every day.</p>

<p>But the most important point is, your progress needs to be easily trackable. With Starting Strength it’s pretty simple, your goal is to add ~5 pounds each time you go to the gym.</p>

<p>If strength is not your goal, there are many programs available. Check out this <a href="http://www.rohitnair.net/pp/">program picker</a>.</p>

<h4 id="track-your-progress">Track your progress</h4>

<p>I’ve tried many iPhone apps to track my progress. The most fun is <a href="http://fitocracy.com">Fitocracy</a>. There’s a game aspect to it that helped me a lot at the beginning. <a href="https://www.fitocracy.com/profile/macournoyer">Follow me here</a> on Fitocracy.</p>

<p>A lot of my progress at the beginning was made by improving my techniques. Mastering something new is also a very rewarding experience and I found learning about better ways the squat, bench press and deadlift to be fascinating.</p>

<h4 id="set-goals">Set goals</h4>

<p>I like to use this site to set my goals: <a href="http://www.strstd.com/">Strength Standards</a>.</p>

<p>A simple goal could be to go from Novice to Intermediate level. Don’t be too audacious and revise your goals if you’re losing motivation. But make sure you’re always progressing, ie. increasing weigths.</p>

<h4 id="consistency-and-intensity">Consistency and intensity</h4>

<p>Those are the two keys to make progress. Make a schedule that is reasonable and that you can follow in the long term.</p>

<p>And here’s the most important part. When you go to the gym: make it INTENSE! If you’re not progressing, you’re either not eating, sleeping or trying hard enough. Forget what you though your body could do. It can lift way more than you think!</p>

<p>I’ve been through some incredible pain to make the progress that I have. But this increases the feeling of accomplishment you get afterwards. It also thought me a lot about pushing harder and more brave in other parts of my life.</p>

<h4 id="a-few-more-tips">A few more tips</h4>

<p>One big problem I had at the beginning was caused by breathing. I was thought that it’s bad to hold your breath when pushing. It’s actually important to hold your breath when lifting heaving to protect your internal organs. This is called the <a href="http://en.wikipedia.org/wiki/Valsalva_maneuver">Valsalva Maneuver</a>. It’s all explained in details in the <a href="http://www.amazon.com/Starting-Strength-3rd-Mark-Rippetoe/dp/0982522738">Starting Strength book</a>.</p>

<p>Regarding supplements. After some research, I ended up with the following combination. Whey protein isolate, creatine, Omega 3 and Vitamin D everyday. And BCAA around trainings. Check out <a href="http://examine.com/">Examine.com</a> to get the details about all those.</p>

<p>One last thing that helped me a lot was to get a <a href="http://www.amazon.com/Valeo-6-Inch-Padded-Leather-Belt/dp/B0007KN6ZY">training belt</a>. I’d recommend getting one once you reach intermediate level. It will help you stabilize your back and torso.</p>

<h4 id="diet">Diet</h4>

<p>I use to follow <a href="http://macournoyer.com/blog/2011/12/06/if/">a strict diet</a>. I tried a few. Nowadays I don’t, but I still do intermittent fasting. But one thing is for sure. If you want to increase you strength, the more you eat the better. The math is pretty simple, try to optimize to get the most protein per calories you consume.</p>

<p>In summary, lifting heavy things is incredibly rewarding, a nice way to get in shape and a great excuse to stuff your face with copious amounts of meat. Seriously. What more could you want?</p>

<p><a href="https://www.fitocracy.com/profile/macournoyer">Join me on Fitocracy</a> and lets lift together!</p>]]></content><author><name></name></author><summary type="html"><![CDATA[So you’re sitting at a computer all day packing on the pounds? Thinking about signing up to the gym to keep in shape? But hey! Most of us have been there. Sign-up for a few months and give up after a few weeks right? I’ve been there many times. But for the last two years and a half I did manage to keep in good shape by going to the gym. So I would like to share with you what worked for me.]]></summary></entry><entry><title type="html">Rebuilding Node’s Event Loop</title><link href="http://macournoyer.com/blog/2013/06/25/event-loop/" rel="alternate" type="text/html" title="Rebuilding Node’s Event Loop" /><published>2013-06-25T00:00:00+00:00</published><updated>2013-06-25T00:00:00+00:00</updated><id>http://macournoyer.com/blog/2013/06/25/event-loop</id><content type="html" xml:base="http://macournoyer.com/blog/2013/06/25/event-loop/"><![CDATA[<p>I am a big believer in mastering your tools to become a better developer. And the best way to master your tools is to understand how they are made.</p>

<p>Do you know what’s happening inside Node.js or EventMachine?</p>

<p>There’s an event loop. So there must be a loop somewhere, right? A loop handling events. Let’s take a look…</p>

<h4 id="the-loop">The Loop</h4>

<p>Event loops like the one in Node or EventMachine are designed to react to I/O events. This could be an incoming connection, data arriving on a socket, etc. What’s more, it must react to these events extremely quickly. Like most things in software, the simplest design is usually the fastest. And event loops are usually very simple.</p>

<p>First, it consists of an endless loop:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">while</span> <span class="p">(</span><span class="kc">true</span><span class="p">)</span> <span class="p">{</span>
  <span class="p">...</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Everything will happen in that loop. All of your Node programs will be running inside that loop. Which is similar to the loop you’ll find in virtual machines and emulators, where an actual processor is simulated instead.</p>

<h4 id="a-turn-in-the-loop">A Turn in the Loop</h4>

<p>Somewhere in the loop, your process will wait for I/O events to happen. Luckily, most operating systems come with a function that allows us to do just that. Several options exist, such as kqueue on Mac OS, epoll on Linux. The most portable (but slowest) one is <code class="language-plaintext highlighter-rouge">select</code>. For more on this, see <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/select.2.html">select(2)</a>.</p>

<p><code class="language-plaintext highlighter-rouge">select</code> watches a bunch of I/O objects (files, sockets) and lets you know when something happens. It looks something like this:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">while</span> <span class="p">(</span><span class="kc">true</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// That's our loop</span>
  <span class="kd">var</span> <span class="nx">events</span> <span class="o">=</span> <span class="nx">select</span><span class="p">(</span><span class="o">&lt;</span><span class="nx">I</span><span class="o">/</span><span class="nx">O</span> <span class="nx">objects</span> <span class="nx">to</span> <span class="nx">watch</span><span class="o">&gt;</span><span class="p">)</span>
<span class="p">}</span>
</code></pre></div></div>

<h4 id="react">React</h4>

<p>At this point in the loop, we know an event has occurred. We must react to those events. In Node and many other event-based systems, this is done via callbacks.</p>

<p>In your Node program, you’ll define callbacks like so:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">object</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="dl">'</span><span class="s1">read</span><span class="dl">'</span><span class="p">,</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> <span class="p">...</span> <span class="p">})</span>
</code></pre></div></div>

<p>This will register the callback inside the event loop, so that it knows what to do when this event happens. Introducing that in our loop, we’ll end up with the following:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">while</span> <span class="p">(</span><span class="kc">true</span><span class="p">)</span> <span class="p">{</span>
  <span class="kd">var</span> <span class="nx">events</span> <span class="o">=</span> <span class="nx">select</span><span class="p">(</span><span class="o">&lt;</span><span class="nx">I</span><span class="o">/</span><span class="nx">O</span> <span class="nx">objects</span> <span class="nx">to</span> <span class="nx">watch</span><span class="o">&gt;</span><span class="p">)</span>
  
  <span class="nx">events</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">event</span><span class="p">)</span> <span class="p">{</span>
    <span class="kd">var</span> <span class="nx">callback</span> <span class="o">=</span> <span class="nx">findCallbackForEvent</span><span class="p">(</span><span class="nx">event</span><span class="p">)</span>
    <span class="nx">callback</span><span class="p">()</span> <span class="c1">// This calls the callback function</span>
  <span class="p">});</span>
<span class="p">}</span>
</code></pre></div></div>

<p>After we’re done executing all of the callbacks, we’re ready for another turn in the loop – it’ll patiently wait for other I/O events to happen.</p>

<h4 id="but-theres-more">But There’s More!</h4>

<p>This is a simplification of how things work internally. However, even if the Node event loop is a little more complex than that, the structure is the same. It’s still a loop using <code class="language-plaintext highlighter-rouge">select</code> (or a variation), and triggering callbacks.</p>

<p>Still not sure how this allows huge amounts of concurrent connections to be handled by a server? Or you’d like to dive deeper into event loops and how it works in Node, and how other features such as <code class="language-plaintext highlighter-rouge">setTimeout</code> are implemented? Join the next edition of my online class: <a href="http://truthabouteventloops.com/">JOIN NOW</a>.</p>

<p>Everything is online. You can ask questions. You’ll get exercises. And you’ll also get recordings of the class to watch again at your leisure.</p>

<p>The class already helped a number of developers master Node and EventMachine. Here’s what one of them had to say:</p>

<blockquote>
  <p>I don’t know where to begin. I am blown away. Other online “classes” that I have attended are very lackluster compared to your class.<br />
  The format was amazing, […], building on top of each lesson as we progressed.<br />
  […]<br />
  I am not sure it could have been done better. This is complicated stuff, and I feel you have gone well above expectations to help understand the event loop.<br />
  I can easily say that I have leveled up - it has changed my thinking on event driven programs. Not just in Node but for Ruby as well.<br />
  <em>- Tom Buchok</em></p>
</blockquote>

<p>The previous edition was a great success and sold out quickly. I’m expecting this one to sold out very soon too. So if you’re interested, <em>“book now”:http://truthabouteventloops.com/</em>!</p>]]></content><author><name></name></author><summary type="html"><![CDATA[I am a big believer in mastering your tools to become a better developer. And the best way to master your tools is to understand how they are made.]]></summary></entry><entry><title type="html">Good coders copy, great coders steal</title><link href="http://macournoyer.com/blog/2013/06/14/great-coders/" rel="alternate" type="text/html" title="Good coders copy, great coders steal" /><published>2013-06-14T00:00:00+00:00</published><updated>2013-06-14T00:00:00+00:00</updated><id>http://macournoyer.com/blog/2013/06/14/great-coders</id><content type="html" xml:base="http://macournoyer.com/blog/2013/06/14/great-coders/"><![CDATA[<blockquote>
  <p>Good artists copy, great artists steal. <em>- Pablo Picasso</em></p>
</blockquote>

<p>What Picasso meant is that good artists duplicate the work of other artists without changing it. But great artists take the work of other artists and make it their own.</p>

<p>I believe programming can be an art, or at least something we should aim for. (For the record, here’s my favorite piece of art… err! code, <a href="http://underpop.free.fr/l/lua/docs/a-no-frills-introduction-to-lua-5.1-vm-instructions.pdf">Lua’s bytecode</a>. If you have the patience to wrap you head around it, I guarantee you’ll believe me when I say this is a piece of art. But let’s stay on track here…)</p>

<p>To become a better programmer you have to first copy, and then steal.</p>

<h4 id="copying">Copying</h4>

<p>A painter that copies another painter’s work, for example, will reproduce every lines and colors one at the time. This makes you realize how many parts come into play to make an amazing piece of art (or software). So when I say copy, I certainly don’t mean <em>copy-paste</em> code from StackOverflow. I mean: <em>recode the thing</em>, line for line or in your own style or language, by looking at the original.</p>

<p>This might seem dumb at first, but it works for the same reason taking notes helps you remember things. Even if you don’t go back to read them. It’s also better than simply reading the code. As you can’t get lazy and skim over some parts.</p>

<p>The first open source project I ever created was called <a href="http://webaccept.sourceforge.net/">WebAccept</a>. An horrible idea I know… But I learned so much! I copied most of the design and code from NAnt, also a copy, or as they said: a .NET port of Ant, the Java build too, which probably started as a copy of Make. That project taught me more than I ever learned in school and at work about good software design, documentation, tests and all.</p>

<p>I’ve been applying the same approach ever since. With Thin, I copied Mongrel. With TinyRB, I copied TinyPy and Lua. Each time learning more and more.</p>

<p>That’s why I think the best way to learn is to copy, recode, recreate from scratch. And also why I use this approach in all my presentations and <a href="http://classes.codedinc.com">classes</a>.</p>

<h4 id="stealing">Stealing</h4>

<p>Stealing is the next level. You can copy some code and still not understand how it works. You can also copy some code and not see a better way to do it. But, you become great when you adapt the code to make it better.</p>

<p>This is how the world of software evolves. Making baby steps towards greatness by building on the work of others before us. Making things a tiny bit better each time. There should be no shame in this kind of stealing.</p>

<p>After copying Thin from Mongrel almost line for line, I rewrote it six times to <em>steal it</em> and make it my own.</p>

<h4 id="lets-copy-together">Lets copy together!</h4>

<p>OK! Want to give it a try?</p>

<p>To get you started and show you how I do it, I’ll be teaching a new class in which I’ll rebuild a Ruby web server from scratch.</p>

<p>And here’s the kick… it’s free!</p>

<p>Sign-up bellow and join me this <em>Friday, June 21st at 1PM ET</em>. It should last about an hour and I’ll take some questions at the end.</p>

<p>However, because of technical limitations, only 100 people can attend it live. But, recordings will be available if you sign up.</p>

<p><a href="http://j.mp/rebuildawebserver"><img src="/images/join_class_button.png" /></a></p>

<p>All you need is basic understanding of web dev with Ruby (with Rails, Sinatra or other) and a browser with Flash.</p>

<p>I hope to see you in class! :)</p>]]></content><author><name></name></author><summary type="html"><![CDATA[Good artists copy, great artists steal. - Pablo Picasso]]></summary></entry><entry><title type="html">Two Years Ago and A Quarter Million Dollar Later</title><link href="http://macournoyer.com/blog/2013/04/10/two-years-ago/" rel="alternate" type="text/html" title="Two Years Ago and A Quarter Million Dollar Later" /><published>2013-04-10T00:00:00+00:00</published><updated>2013-04-10T00:00:00+00:00</updated><id>http://macournoyer.com/blog/2013/04/10/two-years-ago</id><content type="html" xml:base="http://macournoyer.com/blog/2013/04/10/two-years-ago/"><![CDATA[<p>Two years ago, I left my job with a very ambitious goal: never work for anyone else but me. This included contract work.</p>

<p>It was real test in self-confidence and determination. <a href="/blog/2011/05/02/working-for-me/">But my first month of working for myself was a great success</a>. I was off to a good start. And I’m glad to say that things continued going increasingly well after that.</p>

<p>Here are the details.</p>

<h3 id="products">Products</h3>

<p>With consulting out of the question, products were my only source of income. As you’ll see, most of my products are info-products, packaging information in various formats.</p>

<p>In the last two years I released five products:</p>

<ul>
  <li><a href="http://owningrails.com/">Owning Rails Masterclass</a></li>
  <li><a href="http://proglangmasterclass.com/">The Programming Language Masterclass</a></li>
  <li><a href="http://truthabouteventloops.com/">The Truth About Event Loops Online Masterclass</a></li>
  <li><a href="http://dresssed.com/">Dresssed - Premium Rails Themes</a></li>
  <li><a href="http://copywritingforgeeks.com/">Copywriting For Geeks</a></li>
  <li>And updated <a href="http://createyourproglang.com/">Create Your Own Programming Language</a></li>
</ul>

<p>I applied a systematic approach in validating and launching each one of those. All became profitable from day one (I describe some of my techniques in <a href="http://copywritingforgeeks.com/">Copywriting For Geeks bonuses</a>). But my classes are the ones generating most of my revenues. This is why I have three. When you find something that works well and that you love to do, you crank it to eleven.</p>

<p>I also created a <a href="http://codedinc.com/">proper company</a> and moved all of my products there.</p>

<h3 id="numbers">Numbers</h3>

<p>Those two years also marked another important milestone. I recently crossed the $250,000 mark in sales. While I don’t think this is exceptional, I’m extremely proud of it. Especially proud of the fact that all of it came from my products, that I created from scratch. I’m now making a living entirely with the things I passionately create in my tiny home office and that feels awesome!</p>

<p>I should also note that I took a lot of weeks and sometimes several months off instead of expanding my business. Had I been more proactive, that number could easily be higher. But I made it a rule not get into any business which would take control of my time. And allowed myself to wander without too much guilt.</p>

<h3 id="its-not-that-hard">It’s not that hard</h3>

<p>A lot of people will say you have to make plenty of sacrifices to have a successful business. Sacrifice your health, time with your family and everything else. I found that a business is everything you want it to be. So it <strong>can</strong> be a bunch of sacrifices if you want it to be or it can be something else. That is the beauty of it all. If you want to work more, you can, and you will be compensated. Not by a pat on the back from your boss, but by more money in your pockets and more customers thanking you. It’s up to you to make those decisions and part of what makes building a business such an empowering and scary adventure.</p>

<p>If you read somewhere that you have to max 10 credit cards, gain 20 pounds and work 15 hours a day to make your business succeed, it’s a lie. In fact, my finances are going great, I actually lost 20 pounds and have worked fewer than 15h per week.</p>

<p>The hard part is not the sacrifices, but the change in mindset you need to make. Putting your stuff out there and asking people to pay you money, constantly promoting your stuff, accepting that some will dislike your products, living in the fear of losing it all and occasional self-doubt can be though challenges.</p>

<h3 id="you-can-do-it">You Can Do It!</h3>

<p>Be my own boss and not have anyone dictate my schedule or interests has been my grand professional goal for as long as I can remember. So don’t be fooled in thinking it took me two years to get where I am today, it took me twelve or more.</p>

<p>Twelve years ago, I was unable to get any job as a software developer. Sitting in my room at my parents house, I furiously coded a VB6 application with the intention of selling it. But didn’t know a thing about where to go from there. Didn’t know anyone who knew anything about that either. Didn’t believe starting a business was possible for people with questionable social skills like me.</p>

<p>If you’re dreaming of being your own boss and creating a business too, here are a few advices:</p>

<ul>
  <li>Start small (give away stuff, open source, etc.) and use your successes to build up your confidence, credibility and authority.</li>
  <li>Start by copying and adapting successful businesses (but make sure they are successful first).</li>
  <li>Your new passions are sales, marketing and advertising.</li>
  <li>Create the best products you can. I promise, people will notice how much you care someday (if they haven’t already).</li>
  <li>Be patient, but determined.</li>
</ul>

<h3 id="thank-you">Thank You!</h3>

<p>You know what makes or breaks a business? Customers. And boy did I found great ones!</p>

<p>If I have anyone to thank for my success it’s you who bought my products. Thank you! None of this would have been possible without your trust, feedback, patience and encouragements. You have changed my life and I can’t never thank you enough for it.</p>

<p>Most of my customers are now referred by other customers who enjoyed my products enough not only to buy and use them, but who tell others about it. That feels incredibly great!</p>]]></content><author><name></name></author><summary type="html"><![CDATA[Two years ago, I left my job with a very ambitious goal: never work for anyone else but me. This included contract work.]]></summary></entry><entry><title type="html">My experience with intermittent fasting</title><link href="http://macournoyer.com/blog/2011/12/06/if/" rel="alternate" type="text/html" title="My experience with intermittent fasting" /><published>2011-12-06T00:00:00+00:00</published><updated>2011-12-06T00:00:00+00:00</updated><id>http://macournoyer.com/blog/2011/12/06/if</id><content type="html" xml:base="http://macournoyer.com/blog/2011/12/06/if/"><![CDATA[<p>I’m surely not the first programmer to mention the side effects of being in front of a computer all day. Right after getting a job, I started packing on pounds and my health kept degrading.</p>

<p>Reading Tim Ferris’ <a href="http://www.fourhourbody.com/">Four Hour Body</a> got me the kick to try a diet. His is called Slow-Carb. Basically: no bread/pasta, no dairy, no fruits, but one cheat day per week. Gotta say it worked quite well and was surprisingly easy to follow. I lost about 25 pounds in a few months and maintained that weight ever since.</p>

<p>But during that time I also got into strength training, but noticed I made very little progress and felt my energy level was pretty low. So I went on to try something else. Also no carbs and no dairy seemed a little weird to me.</p>

<h3 id="enter-intermittent-fasting">Enter Intermittent Fasting</h3>

<p>So I ended up on <a href="http://www.leangains.com/2010/04/leangains-guide.html">LeanGain.com</a>.</p>

<p>The premise is you fast for 16h+ and eat during the remaining hours of the day. Which basically means you skip breakfast.</p>

<p>LeanGain also adds fasted training, meaning you even train before eating, after ~15h of fast! Crazy uurg!</p>

<h3 id="omg-but-breakfast-is-the-most-important-meal-of-the-day">OMG! But breakfast is the most important meal of the day!</h3>

<p>There have been numerous studies showing that skipping breakfast makes you fat and all. But apparently, other studies are proving this wrong. People skipping breakfast either already have bad eating habits or fasting make them eat more in subsequent meals. Which is why I tracked my calories, carbs, fat and proteins closely at first.</p>

<p>Intermittent fasting actually has a bunch of <a href="http://en.wikipedia.org/wiki/Intermittent_fasting#Studies">health benefits</a>. Some studies even show it can lower blood pressure. I’ve had hypertension for a few years and medication was the next step. So that was enough to convince me to try it for a few months.</p>

<p>I’m not a health expert in any way, so I encourage you read about <a href="http://www.leangains.com/2010/10/top-ten-fasting-myths-debunked.html">fasting myths here</a> by the author of LeanGain.</p>

<h3 id="results">Results</h3>

<p>I’ve been following the LeanGain approach for almost two months now and here are my results.</p>

<p>I had been maintaining my weight around 175 pounds and ~18% of body fat (143.5 of lean mass) for close to a year. I was unable to get lower and also unable to get more strength. Now after ~two months I’m at 170 pounds and ~14.5% body fat (145.35 of lean mass).</p>

<p>So I gained ~1.85 pounds of lean mass (musclez!) and lost ~6.85 pounds of fat in a little less than two months.</p>

<p>My strength has also been increasing:</p>
<ul>
  <li>Bench press: from 160 pounds to 185 pounds</li>
  <li>Squat: from 225 pounds to 275 pounds</li>
  <li>Deadlift: from 185 pounds to 315 pounds (was scared at first to try this, which explains the very low initial number)</li>
</ul>

<p>And… surprise surprise! My blood pressure dropped back to normal in just one month!</p>

<p>Right before starting on October 23: 155/83
On November 24: 133/84</p>

<p>Although it was hard during the first two weeks. I actually now feel more focused during the morning when fasting. And I also have more time during the AM as I don’t need to eat/prepare breakfast.</p>

<h3 id="warning">WARNING!</h3>

<p>Obviously, I’m not a doctor. I don’t know what I’m talking about here and am simply reporting my results. Do any of this at your own risk.</p>]]></content><author><name></name></author><summary type="html"><![CDATA[I’m surely not the first programmer to mention the side effects of being in front of a computer all day. Right after getting a job, I started packing on pounds and my health kept degrading.]]></summary></entry><entry><title type="html">How Your Code Is Executed</title><link href="http://macournoyer.com/blog/2011/11/21/proglang/" rel="alternate" type="text/html" title="How Your Code Is Executed" /><published>2011-11-21T00:00:00+00:00</published><updated>2011-11-21T00:00:00+00:00</updated><id>http://macournoyer.com/blog/2011/11/21/proglang</id><content type="html" xml:base="http://macournoyer.com/blog/2011/11/21/proglang/"><![CDATA[<p>I remember as a kid I was so excited when something broke in the house, a phone, the TV or the Nintendo. That meant I got to open the thing and look at how it worked. Of course I had to nag my parents for it and they sometimes questioned if I was the one who broke it in the first place simply to crack it open. Maybe once… but not more, I swear!</p>

<p>Later on I discovered programming and became fascinated by how easy it was to create things with it. It took me a few years, but I finally got the itch to crack it open and learn how programming languages are made.</p>

<p>Since then, I believe I became a better programmer simply because programming languages are the tools we use, and <em>understanding how your tools work, in any profession, art or science, is the best way to master our craft</em>.</p>

<h3 id="overview-of-a-language">Overview of a language</h3>

<p>Here’s a quick overview of how a typical programming language is structured:</p>

<p><img src="/images/lang.png" alt="alt text" /></p>

<p>Here’s a walkthrough:</p>

<ul>
  <li>The <em>lexer</em> will take your code, split it into <em>tokens</em> and tag them. If your code was in english, that would be like splitting each sentences into words and tagging each word as an adjective, noun or verb.</li>
  <li>Then the <em>parser</em> takes those tokens and try to derive meaning from it by matching tokens with a set of rules defined in a grammar. This is where we define what constitute an expression, a method call, a local variable and such in our language. The result of that parsing phase is a tree of <em>nodes</em>, called AST for Abstract Syntax Tree.</li>
  <li>Now, if our language is a tree walker interpreter (like ruby &lt; 1.9), the <em>interpreter</em> will browse the nodes one by one and execute the action associated with each type of node. It’s not very efficient, so that’s why most languages compile to bytecode instead of keeping the nodes in memory and executing from them.</li>
  <li><em>Bytecode</em> is very close to machine code, but at the same time close to our language source too. The trick is to bring it as close to the machine as possible to get higher performance and as close to our language as possible to make it easier to compile. Once we have that bytecode, we run it through the <em>virtual machine</em>. It will walk through the bytecode executing actions associated with each byte.</li>
  <li>While executing, our VM or interpreter will modify the runtime. The <em>runtime</em> is where our program lives. It’s the living world in which our program is executing. When you create objects or call methods, this is all happening in the runtime. Having a fast and memory efficient runtime is crucial. This is also where the garbage collector is doing its work.</li>
</ul>

<h3 id="how-bytecode-is-actually-executed">How bytecode is actually executed</h3>

<p>One of the most fascinating thing I learned was how the bytecode is interpreted by the virtual machine. Even though it’s a <em>Virtual</em> machine, it is very close to how the actual physical machine, the processor, work. So understanding this leads to understanding how your whole machine works!</p>

<p>Here’s a small excerpt from my new class: <a href="http://proglangmasterclass.com/">The Programming Language Masterclass</a> explaining how an <code class="language-plaintext highlighter-rouge">if</code> statement is executed at the bytecode level.</p>

<p>A few notes before you watch:</p>

<ul>
  <li>The literal table is where we store hard coded values that appear in our code, such as strings, numbers and method names</li>
  <li>A series of bytes in the bytecode form an instruction, each one telling the VM what to do.</li>
</ul>

<p>All of this is properly introduced and explained during the class.</p>

<iframe width="640" height="480" src="http://www.youtube.com/embed/m1Ob3VVh60U?rel=0" frameborder="0" allowfullscreen=""></iframe>

<p>I hope this clears up a few things. Leave a comment and let me know!</p>]]></content><author><name></name></author><summary type="html"><![CDATA[I remember as a kid I was so excited when something broke in the house, a phone, the TV or the Nintendo. That meant I got to open the thing and look at how it worked. Of course I had to nag my parents for it and they sometimes questioned if I was the one who broke it in the first place simply to crack it open. Maybe once… but not more, I swear!]]></summary></entry><entry><title type="html">Three ways to stimulate your creativity</title><link href="http://macournoyer.com/blog/2011/10/18/creativity/" rel="alternate" type="text/html" title="Three ways to stimulate your creativity" /><published>2011-10-18T00:00:00+00:00</published><updated>2011-10-18T00:00:00+00:00</updated><id>http://macournoyer.com/blog/2011/10/18/creativity</id><content type="html" xml:base="http://macournoyer.com/blog/2011/10/18/creativity/"><![CDATA[<p>Is there something more depression than having zero creativity? You know you want to create something but don’t know what. Or perhaps you have a problem, but can’t find the proper solution. Sometimes your brain is just not in full power. You see all those people on the internets creating amazing things. Why can’t you create stuff like that?</p>

<p>I know the feeling!</p>

<p>I’ve had some very creative times in my life, but I’ve also had some very depressing times where I felt like the dumbest person on earth. Throughout the years, I’ve studied famous creative people and tried various ways to stimulate my creativity.</p>

<p>Here are the three techniques that worked best. Each one worked very well but at different times, often in combination.</p>

<h3 id="1-break-a-habit">1. Break a habit</h3>

<p>The best way to have no creativity is to turn your brain off. When your whole day or week is a routine you don’t even have to think to complete, you’re basically living on autopilot. Changing small things in a routine can have a huge impact on your creativity.</p>

<p>Take a different path to work. Change haircut. Change your lunch menu. Anything small or big will stimulate your brain. I’ve used this technique numerous times.</p>

<p>Also, changing a habit will stimulate you to change other ones. So if you want to change something important, change some small things first, which will give you motivation (doing something new is always exciting isn’t it?). Then, use that motivation and confidence to change something bigger.</p>

<p>The point is to get momentum. This also work for anything you want to accomplish, not only having more creativity.</p>

<h3 id="2-be-alone">2. Be alone</h3>

<blockquote>
  <p>Be alone, that is the secret of invention: be alone, that is when ideas are born. <em>- Nikola Tesla</em></p>
</blockquote>

<p>Solitude is greatly underrated. I believe no serious work, deep thinking or innovation is possible with people around you.</p>

<p>This has nothing to do with being introvert or not. Creating requires a high level of concentration which can’t be reached when there are people around. You can’t still get with people before of after that process to get feedback or re-energize.</p>

<blockquote>
  <p>Without great solitude no serious work is possible. <em>- Pablo Picasso</em></p>
</blockquote>

<p>And by alone, I also mean no IM, Twitter, Facebook or such.</p>

<h3 id="3-get-bored">3. Get bored</h3>

<p>Here’s an easy way to get bored: consume less. Not because I believe consuming is bad, but because I think it forces us to the other side: producing.</p>

<blockquote>
  <p>Necessity is the mother of invention. <em>- Unknown</em></p>
</blockquote>

<p>Get bored long enough and I assure you getting unbored by creating will become a necessity.</p>

<p>I remember having no internet when I was younger on my parents computer. That’s why I first learn to program, there was nothing else to do on that damn thing!</p>

<p>Drop a comment below and let me know if you have any tip of your own to stimulate your creativity!</p>]]></content><author><name></name></author><summary type="html"><![CDATA[Is there something more depression than having zero creativity? You know you want to create something but don’t know what. Or perhaps you have a problem, but can’t find the proper solution. Sometimes your brain is just not in full power. You see all those people on the internets creating amazing things. Why can’t you create stuff like that?]]></summary></entry><entry><title type="html">Free Time</title><link href="http://macournoyer.com/blog/2011/07/26/free-time/" rel="alternate" type="text/html" title="Free Time" /><published>2011-07-26T00:00:00+00:00</published><updated>2011-07-26T00:00:00+00:00</updated><id>http://macournoyer.com/blog/2011/07/26/free-time</id><content type="html" xml:base="http://macournoyer.com/blog/2011/07/26/free-time/"><![CDATA[<p>One question I get all the time when I release something is: <em>how do you find the time?</em> Although this is false, you don’t find free time, you make it. Because as soon as your time becomes free you fill it with an activity: playing, reading, sleeping, thinking. This is <a href="http://en.wikipedia.org/wiki/Parkinson's_Law:">Parkinson’s Law</a> your daily activities expand to fill the time available.</p>

<p>Time is your most valuable asset. With time you can make whatever you want, be it money or anything else. With some money you can afford some more time and with some more time you can get some more money. Success builds upon successes.</p>

<p>A few years ago, after releasing my first successful open-source projects, some people told me: “appreciate the time you have now, because once you have kids you won’t have time for this anymore”. A year later, my daughter was born, the same year, I released <a href="http://code.macournoyer.com/tinyrb/">tinyrb</a> the most complex coding project I ever did. Now I have two kids, more projects than ever and managed to quit my job doing only what I love.</p>

<h3 id="how-to-make-time">How to Make Time?</h3>

<p>Everyone’s life is different. Of course, now I get pretty much all the time that I want (but I still have to plan for it). But I’ve always found ways to make time for my projects. Here’s a quick recap of hours I saved to dedicate to my projects when I had a job.</p>

<ul>
  <li>Work from home: -2h/day</li>
  <li>Sleep less: -2h/day</li>
  <li>Don’t watch TV: -2h/day</li>
</ul>

<p>That makes an extra <em>6 hours per day</em>. 30 hours per week (without the weekends). <em>That’s almost another workweek right there</em> and I haven’t cut a minute from the things I love, like spending time with my family and reading books. I don’t always spent all this time on my projects, but when I have an idea, I can make things happen in a week or so. The point is, this is my time, I decide what I do with it.</p>

<p>Here are a few more examples of useless activities you might have done recently: checked-out Google+, Installed OS X Lion.
You might be thinking: “but I have to keep up to date with latest technologies”. I’m not saying you shouldn’t, but you certainly don’t need to try every new technology that comes out the minute it comes out. Let other people filter it for you.</p>

<h3 id="this-is-hard-i-need-my-night-of-sleep-and-forget-about-working-from-home">This is Hard, I Need My Night of Sleep and Forget About Working From Home</h3>

<p>Yeah, life is hard, I agree with that.</p>

<p><a href="http://www.fourhourworkweek.com/">The Four Hour Workweek</a> has a chapter on how to work your way up to working from home full-time. It’s hard, takes time, guts and determination. I started with only one occasional day per week, then a few more, then full-time a year later. You can plan for it and make concessions (like a smaller salary, remember: time is your most valuable asset).</p>

<h3 id="how-to-find-motivation">How to Find Motivation?</h3>

<p>I remember a year ago, I found this video and that was quite a revelation to me. I know it can be cheesy, but sometimes that tasty cheese is all you need to get the energy needed :) (oh what a cheesy pun!). It all boils down to: how bad do you want it? Not bad enough if you can’t make time for it.</p>

<iframe width="425" height="349" src="http://www.youtube.com/embed/JRfoFGGyRvU" frameborder="0" allowfullscreen=""></iframe>

<blockquote>
  <p>When you want to succeed as bad as you want to breath, then you’ll be successful.</p>
</blockquote>]]></content><author><name></name></author><summary type="html"><![CDATA[One question I get all the time when I release something is: how do you find the time? Although this is false, you don’t find free time, you make it. Because as soon as your time becomes free you fill it with an activity: playing, reading, sleeping, thinking. This is Parkinson’s Law your daily activities expand to fill the time available.]]></summary></entry><entry><title type="html">Why Geeks Don’t Believe in Copywriting</title><link href="http://macournoyer.com/blog/2011/07/12/copywriting/" rel="alternate" type="text/html" title="Why Geeks Don’t Believe in Copywriting" /><published>2011-07-12T00:00:00+00:00</published><updated>2011-07-12T00:00:00+00:00</updated><id>http://macournoyer.com/blog/2011/07/12/copywriting</id><content type="html" xml:base="http://macournoyer.com/blog/2011/07/12/copywriting/"><![CDATA[<p>Copywriting is the art/science of selling with words. Most geeks do not believe in copywriting. Long copy can’t sell, right? Who reads a single sentence in Apple’s copy? All you need is a fancy product name and an incredible list of features, right?</p>

<p>Wrong, wrong and … wrong! And I’ll explain why in a minute.</p>

<p>Various styles of copy work depending on the stage of sophistication of the market and their state of awareness.</p>

<h3 id="states-of-awareness">States of awareness</h3>

<p>How aware of your product and their needs is your market?</p>

<ol>
  <li>The most aware: everybody knows about your product, no need for long copy, state the price and what’s new about it.</li>
  <li>The customer knows of the product but doesn’t yet want it.</li>
  <li>The prospect knows he wants what product does, but doesn’t know yet there is a product.</li>
  <li>The prospect has a need, recognize the need, but doesn’t recognize the connection between need &amp; your product.</li>
  <li>Completely unaware market.</li>
</ol>

<p>Most mainstream copy is cheesy to geeks because we have a very high state of awareness (state 1-2).</p>

<h3 id="sophistication-of-the-market">Sophistication of the market</h3>

<p>Copy also depends on how many products have been there before you. This is called the sophistication of the market.</p>

<p>Here are the 4 stages of sophistication of a market with a sample headline describing each.</p>

<p><em>Stage 1:</em> (First to market) keep it simple, eg.: “Lose ugly fat”
<em>Stage 2:</em> Push claims to extreme, answer objections, eg.: “Lose up to 47 pounds in 4 weeks or get $40 back”
<em>Stage 3:</em> Find new mechanism, eg.: “First wonder drug for losing fat”
<em>Stage 4:</em> Expand on new mechanism, push it to extreme, answer objections, eg.: “First no diet wonder drug for losing fat”</p>

<p>Those headline are old-hat. Style changes but strategies don’t.</p>

<h3 id="learn-to-write-amazing-copy-now-for-free-zomgbbq">Learn to write amazing copy NOW, for FREE! ZOMGBBQ!</h3>

<p>I have to admit, my interest in copywriting was caused by an over-exposure to <a href="http://www.amctv.com/shows/mad-men">Mad Men</a>. After watching the four seasons a dozen times, I carefully studied <a href="http://www.amazon.com/Influence-Psychology-Persuasion-Robert-Cialdini/dp/0688128165">Influence</a>, by Robert B. Cialdini, the mythical (and out of print) <a href="http://amzn.com/0932648541">Breakthrough Advertising</a>, by Eugene Schwartz, a bunch of other books and bought a crap load of videos, PDFs and online tutorials about copywriting.</p>

<p>After applying some of this stuff, I started <a href="/blog/2011/05/02/working-for-me/">selling a lot more</a> and my life began to change quite drastically :).</p>

<p>It took me some time to admit this was due to my copywriting skills, but I was literally getting emails from customers saying: “Your tag line hooked me”, “[…] then I read your [product] description and that sealed it” and “this sentence convinced me”.</p>

<p>So, I’ve decided to pack all my learnings in a small eBook for easy and quick consumption by you!</p>

<p>And … it’s <em>FREE</em>! For now at least ;)</p>

<p><em>Get it at “copywritingforgeeks.com”:http://copywritingforgeeks.com/</em></p>

<p>I hope you like it!</p>

<p><em>Note: The stages of sophistication and states of awareness are from the book <a href="http://amzn.com/0932648541">Breakthrough Advertising</a>, by Eugene Schwartz.</em></p>]]></content><author><name></name></author><summary type="html"><![CDATA[Copywriting is the art/science of selling with words. Most geeks do not believe in copywriting. Long copy can’t sell, right? Who reads a single sentence in Apple’s copy? All you need is a fancy product name and an incredible list of features, right?]]></summary></entry></feed>