<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Arnaud Brousseau</title>
    <link>https://arnaudbrousseau.com/</link>
    <description>Notes on cryptography, security, and software engineering by Arnaud Brousseau</description>
    <language>en-us</language>
    <lastBuildDate>Sun, 20 Sep 2026 22:43:35 -0500</lastBuildDate>
    <atom:link href="https://arnaudbrousseau.com/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>I Am a Strange Loop</title>
      <link>https://arnaudbrousseau.com/notes/i-am-a-strange-loop.html</link>
      <pubDate>Sun, 20 Sep 2026 22:43:35 -0500</pubDate>
      <guid>https://arnaudbrousseau.com/notes/i-am-a-strange-loop.html</guid>
      <description>&lt;p&gt;&amp;ldquo;I Am a Strange Loop&amp;rdquo; (book by Douglas Hofstadter, &lt;a href=&#34;https://www.amazon.com/dp/0465030793/&#34;&gt;Amazon link&lt;/a&gt;) changed how I view consciousness. It&amp;rsquo;s not a topic I often think about, but it&amp;rsquo;s always been puzzling to me. There&amp;rsquo;s this aura of &amp;ldquo;magic&amp;rdquo; around it. It&amp;rsquo;s supposed to be sacred. It&amp;rsquo;s supposed to be what makes us human. And it&amp;rsquo;s supposedly beyond scientific comprehension, which has always frustrated me as a firm atheist and scientist.&lt;/p&gt;
&lt;p&gt;I originally picked up &amp;ldquo;I Am a Strange Loop&amp;rdquo; because I loved reading &amp;ldquo;Gödel, Escher, Bach&amp;rdquo; (&lt;a href=&#34;https://www.amazon.com/G%C3%B6del-Escher-Bach-Eternal-Golden/dp/0465026567&#34;&gt;Amazon link&lt;/a&gt;), another book by Douglas Hofstadter, considered a &amp;ldquo;must-read&amp;rdquo; in the computer science field. There&amp;rsquo;s a clear thread between the two books: you&amp;rsquo;ll find some Escher, some Bach, and a &lt;strong&gt;whole lot&lt;/strong&gt; of Gödel in &amp;ldquo;I Am a Strange Loop&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;There was a before and after reading &amp;ldquo;I Am a Strange Loop&amp;rdquo; for me. It&amp;rsquo;s the first explanation of consciousness that feels satisfying. Below I&amp;rsquo;m trying to organize my own thinking about it, and pinpoint what it clarified.&lt;/p&gt;
&lt;h2 id=&#34;consciousness-as-a-spectrum&#34;&gt;Consciousness as a spectrum&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;My thinking before&lt;/strong&gt;: consciousness is an attribute. Animals have consciousness, so do humans. Bacteria or viruses do not. I never stopped to analyze the full spectrum.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;After &amp;ldquo;I Am a Strange Loop&amp;rdquo;&lt;/strong&gt;: consciousness is a spectrum. It feels uncomfortable to &amp;ldquo;rank&amp;rdquo; living beings in this way but looking back it seems obvious that a mosquito&amp;rsquo;s consciousness should be considered &amp;ldquo;less than&amp;rdquo; the consciousness of a rabbit or a mouse. Here&amp;rsquo;s the hierarchy introduced by Hofstadter in the first chapter:&lt;/p&gt;
&lt;center&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/cone-of-consciousness.png&#34; alt=&#34;Cone of consciousness (I Am a Strange Loop, chapter 1)&#34; style=&#34;max-width: 560px&#34; /&gt;&lt;/center&gt;
&lt;h2 id=&#34;causality-of-patterns&#34;&gt;Causality of patterns&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;My thinking before&lt;/strong&gt;: I subscribed to &amp;ldquo;true&amp;rdquo; cause and effect at the microscopic level. Physics rules the world. If given the choice between an explanation at the macro level or the micro level, I would pick the micro level every single time because it seemed like a &amp;ldquo;deeper&amp;rdquo;, more general explanation.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;After &amp;ldquo;I Am a Strange Loop&amp;rdquo;&lt;/strong&gt;: lower levels can sometimes be worse at explaining &amp;ldquo;what is going on&amp;rdquo;, or can even be irrelevant! Hofstadter gives the example of a complex layout of dominoes, arranged in such a way that you can &amp;ldquo;input&amp;rdquo; an integer by triggering some dominoes, and where the &amp;ldquo;output&amp;rdquo; is read by looking at which chain of dominoes fell. The two possible chains indicate whether the input number is prime or not. Explaining that the &amp;ldquo;prime&amp;rdquo; dominoes fall because 641 is prime is &lt;em&gt;certainly&lt;/em&gt; better than the microscopic explanation which consists of saying that this domino fell because that domino fell because&amp;hellip;and so on. It&amp;rsquo;s better because it explains why this output (&amp;ldquo;true&amp;rdquo;) occurred given a certain input (641). The micro-level answer cannot. This is an important idea: the pattern can be more interesting and illuminating than the individual parts that compose it.&lt;/p&gt;
&lt;p&gt;The second important idea is one of causation: once we agree that the layout of dominoes is testing numbers for primality, is it accurate to say that the primeness of 641 &lt;em&gt;caused&lt;/em&gt; the &amp;ldquo;prime&amp;rdquo; dominoes to fall? Hofstadter says yes, and he thinks that&amp;rsquo;s how consciousness works too. This idea is actually from Roger W. Sperry: in &lt;a href=&#34;https://www.informationphilosopher.com/solutions/scientists/sperry/Mind_Brain_and_Humanist_Values.html&#34;&gt;&amp;ldquo;Mind, Brain, and Humanist Values&amp;rdquo;&lt;/a&gt; he says &amp;ldquo;Who pushes whom around in the population of causal forces that occupy the cranium?&amp;rdquo;. This second idea, that patterns have causal potency, is how we make sense of the world at a macro level: &amp;ldquo;I&amp;rdquo; made my fingers type these words.&lt;/p&gt;
&lt;h2 id=&#34;the-rise-of-strange-loops&#34;&gt;The rise of strange loops&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;My thinking before&lt;/strong&gt;: to be honest I had never given much thought to loops or &amp;ldquo;strange&amp;rdquo; loops. I&amp;rsquo;m a programmer who likes to untangle loops and avoid recursion whenever I can, for clarity&amp;rsquo;s sake. The idea of self-referential statements like quines seemed cute but not profound enough to be exciting to me.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;After &amp;ldquo;I Am a Strange Loop&amp;rdquo;&lt;/strong&gt;: Hofstadter makes a compelling case for strange loops being at the core of consciousness. The first distinction he makes is the difference between reception-based loops and perception-based loops. Reception-based loops are, for example, audio-feedback loops: the microphone picks up the loudspeaker&amp;rsquo;s output, and this loops and loops and loops. Perception-based loops are where things get interesting because the receiver &lt;em&gt;categorizes&lt;/em&gt; and acts based on categories. Perception sorts, augments, and discards.&lt;/p&gt;
&lt;p&gt;Strange loops, he claims, arise when perception loops start to perceive themselves. This is the birth of the &amp;ldquo;I&amp;rdquo; loop. When a baby starts moving their hands and body around they learn by perceiving what happens as a consequence. Gradually they recognize the hand as their own. And they begin to represent themselves as the one moving the hand. This perception loop keeps spinning and categorizing forever. The baby&amp;rsquo;s &amp;ldquo;I&amp;rdquo; loop is constantly reinforced by experiences over years and years and gradually becomes the most unshakable illusion there is: the impression of a separate &amp;ldquo;I&amp;rdquo; that stands outside the process and controls it. There is no &amp;ldquo;out-of-loop&amp;rdquo; controller: the controller is the loop. &amp;ldquo;I&amp;rdquo; is the strange loop.&lt;/p&gt;
&lt;p&gt;Hofstadter draws a beautiful parallel between &amp;ldquo;I&amp;rdquo;-style strange loops and Gödel&amp;rsquo;s Incompleteness theorem. &lt;a href=&#34;https://en.wikipedia.org/wiki/Principia_Mathematica&#34;&gt;&amp;ldquo;Principia Mathematica&amp;rdquo;&lt;/a&gt; (&amp;ldquo;PM&amp;rdquo;) is a carefully constructed set of axioms and rules. The monumental achievement of PM is the derivation, under this very strict set of rules, of a large portion of mathematics. Gödel&amp;rsquo;s Incompleteness theorem proved that there are infinitely many true statements which cannot be proved within PM. And the way he did that is via a strange loop, using the power of encoding. He encoded statements of PM in natural numbers such that arithmetic statements could be read on two levels. He constructed a self-referential &amp;ldquo;true&amp;rdquo; statement, in PM notation, which says &amp;ldquo;I am not provable within PM&amp;rdquo;. If the statement were false, it would be provable, which means PM proves something false. Assuming PM only proves true things, the statement must be true, and therefore unprovable within PM. Checkmate!&lt;/p&gt;
&lt;p&gt;The relationship between Gödel&amp;rsquo;s formula and consciousness is the &amp;ldquo;loop back&amp;rdquo;: the formula is able to talk &amp;ldquo;about&amp;rdquo; PM and its own provability. Highly recommend reading through chapters 9 and 10 for more. And if you have the stomach for it, here&amp;rsquo;s Gödel&amp;rsquo;s original paper: &lt;a href=&#34;https://homepages.uc.edu/%7Emartinj/History_of_Logic/Godel/Godel%20%E2%80%93%20On%20Formally%20Undecidable%20Propositions%20of%20Principia%20Mathematica%201931.pdf&#34;&gt;On Formally Undecidable Propositions of Principia Mathematica And Related Systems&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;on-free-will&#34;&gt;On Free Will&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;My thinking before&lt;/strong&gt;: I had always been a free will skeptic. I&amp;rsquo;m a firm believer in physics, and so the concepts of consciousness and free will seem to escape that. John Conway&amp;rsquo;s lecture series on free will (the &amp;ldquo;Free will lectures&amp;rdquo;, see &lt;a href=&#34;https://www.youtube.com/playlist?list=PLy6vjBBz_zHSq7btLIDoPDQjfoq4kKT2e&#34;&gt;this YouTube playlist&lt;/a&gt;) had put a bit of doubt in my mind. The &lt;a href=&#34;https://en.wikipedia.org/wiki/Free_will_theorem&#34;&gt;Free Will Theorem&lt;/a&gt; states that &amp;ldquo;if we have free will, then so do the particles&amp;rdquo;. So I thought: maybe have free will after all, given quantum mechanics seems to indicate it?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;After &amp;ldquo;I Am a Strange Loop&amp;rdquo;&lt;/strong&gt;: I&amp;rsquo;m leaning back toward in the idea that there is no free will. Douglas Hofstadter makes a really strong case against it. And, mind you, the Free Will Theorem doesn&amp;rsquo;t say that we have free will! It&amp;rsquo;s perfectly compatible with a world where we do not have free will. Quoting from chapter 23, from a section called &amp;ldquo;No such thing as free will&amp;rdquo;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;What, then, is all the fuss about “free will” about? Why do so many people insist on the grandiose adjective, often even finding in it humanity’s crowning glory? What does it gain us, or rather, what would it gain us, if the word “free” were accurate? I honestly do not know. I don’t see any room in this complex world for my will to be “free”.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;He goes on to conclude:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;our decisions are made by an analogue to a voting process in a democracy. Our various desires chime in, taking into account the many external factors that act as constraints, or more metaphorically, that play the role of hedges in the vast maze of life in which we are trapped. Much of life is incredibly random, and we have no control over it. We can will away all we want, but much of the time our will is frustrated.&lt;br&gt;
[&amp;hellip;]&lt;br&gt;
Our will, quite the opposite of being free, is steady and stable, like an inner gyroscope, and it is the stability and constancy of our non-free will that makes me me and you you, and that also keeps me me and you you.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;My view on free will is now similar: yes there are inner conflicts, yes we sometimes make hard decisions, but none of them are a result of &amp;ldquo;free&amp;rdquo; will. It&amp;rsquo;s our inner &amp;ldquo;I&amp;rdquo; loop at work. &amp;ldquo;I&amp;rdquo; have no ability to choose independently of the processes, desires, and accumulated experience of &amp;ldquo;my&amp;rdquo; own strange loop.&lt;/p&gt;
&lt;h2 id=&#34;love-death-and-mirroring&#34;&gt;Love, death, and mirroring&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;My thinking before&lt;/strong&gt;: death and (un)consciousness seemed related, but I never really thought about love as related to consciousness, let alone strange loops! The book fed these ideas to me.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;After &amp;ldquo;I Am a Strange Loop&amp;rdquo;&lt;/strong&gt;: In chapters 16 and 17 Douglas Hofstadter talks about how the loss of his wife affected him. He shares private emails and introduces the idea of mirrored loops: when you get to know another human you can sometimes reason as if you were them. Express their point of view when they&amp;rsquo;re not there. We&amp;rsquo;re internalizing how others react to the outside world in our own brains. The concept of empathy is closely related.&lt;/p&gt;
&lt;p&gt;The idea of loop mirroring is a beautiful one when applied to friendship and loved ones. We&amp;rsquo;ve all experienced the classic &amp;ldquo;wow, if X were here they&amp;rsquo;d go crazy&amp;rdquo; (as their favorite song starts). Hofstadter also applies this to death and disappearance. He explains that in his view a funeral&amp;rsquo;s main purpose is to celebrate the deceased by &amp;ldquo;rekindling&amp;rdquo; the mirrored loops. What a nice way to see the world! Funerals as a celebration and hopeful event. Quoting directly from the book because I can&amp;rsquo;t do it justice otherwise:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;[The] purpose of holding a funeral or memorial service is to reunite the people most intimate with the deceased, and to collectively rekindle in them all, for one last time, the special living flame that represents the essence of that beloved person, profiting directly or indirectly from the presence of one another, feeling the shared presence of that person in the brains that remain&lt;br&gt;
[&amp;hellip;]&lt;br&gt;
Though the primary brain has been eclipsed, there is, in those who remain and who are gathered to remember and reactivate the spirit of the departed, a collective corona that still glows. This is what human love means. The word “love” cannot, thus, be separated from the word “I”; the more deeply rooted the symbol for someone inside you, the greater the love, the brighter the light that remains behind&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Reading this brought me close to tears.&lt;/p&gt;
&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Oh my, do I recommend &amp;ldquo;I Am a Strange Loop&amp;rdquo;! It&amp;rsquo;s a few hundred pages and it starts sort of slow, but it&amp;rsquo;s a journey worth embarking on. Here&amp;rsquo;s an excerpt from the end of the book to round it all up:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;You and I are mirages who perceive themselves, and the sole magical machinery behind the scenes is perception — the triggering, by huge flows of raw data, of a tiny set of symbols that stand for abstract regularities in the world. When perception at arbitrarily high levels of abstraction enters the world of physics and when feedback loops galore come into play, then &amp;ldquo;which&amp;rdquo; eventually turns into &amp;ldquo;who&amp;rdquo;.&lt;br&gt;
[&amp;hellip;]&lt;br&gt;
We human beings are macroscopic structures in a universe whose laws reside at a microscopic level. As survival-seeking beings, we are driven to seek efficient explanations that make reference only to entities at our own level. We therefore draw conceptual boundaries around entities that we easily perceive, and in so doing we carve out what seems to us to be reality.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&#34;whats-next&#34;&gt;What&amp;rsquo;s next&lt;/h2&gt;
&lt;p&gt;A few interesting ideas or leads worth pursuing, after reading &amp;ldquo;I Am a Strange Loop&amp;rdquo;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read &lt;a href=&#34;https://logicmatters.net/igt/&#34;&gt;&amp;ldquo;Gödel without (too many) tears&amp;rdquo;&lt;/a&gt; to dive deeper into Gödel&amp;rsquo;s famous theorem. &amp;ldquo;I Am a Strange Loop&amp;rdquo; introduces the high-level ideas but I&amp;rsquo;d like to understand them at a deeper level.&lt;/li&gt;
&lt;li&gt;Watch &lt;a href=&#34;https://www.youtube.com/watch?v=n8m7lFQ3njk&#34;&gt;Analogy as the core of cognition&lt;/a&gt;, a lecture by Douglas Hofstadter from 2005. There is also &lt;a href=&#34;https://www.amazon.com/dp/0465018475&#34;&gt;&amp;ldquo;Surfaces and Essences&amp;rdquo;&lt;/a&gt;, which seems to be a book about the same set of concepts (the book&amp;rsquo;s subtitle is &amp;ldquo;Analogy as the fuel and fire of thinking&amp;rdquo;).&lt;/li&gt;
&lt;li&gt;Dive deeper into Derek Parfit&amp;rsquo;s &lt;a href=&#34;https://en.wikipedia.org/wiki/Reasons_and_Persons&#34;&gt;&amp;ldquo;Reasons and Persons&amp;rdquo;&lt;/a&gt; which has some original thinking about identities and influenced Douglas Hofstadter in his own thought experiments.&lt;/li&gt;
&lt;li&gt;Read more about &lt;a href=&#34;https://en.wikipedia.org/wiki/Philosophical_zombie&#34;&gt;&amp;ldquo;philosophical zombie worlds&amp;rdquo;&lt;/a&gt;, popularized by David Chalmers (&amp;ldquo;machines &lt;em&gt;that&lt;/em&gt; think&amp;rdquo; vs &amp;ldquo;machines &lt;em&gt;who&lt;/em&gt; think&amp;rdquo;). This makes no sense to me in a way that deserves a double-click. This was introduced in &lt;a href=&#34;https://www.amazon.com/dp/0195117891&#34;&gt;&amp;ldquo;The Conscious Mind: In Search of a Fundamental Theory&amp;rdquo;&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Hofstadter talks about &amp;ldquo;élan mental&amp;rdquo;, taking inspiration from Bergson&amp;rsquo;s &amp;ldquo;élan vital&amp;rdquo;. Going to the source of that term feels worth it. Go read Henri Bergson&amp;rsquo;s &lt;a href=&#34;https://en.wikipedia.org/wiki/Creative_Evolution_(book)&#34;&gt;Creative Evolution&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Another fascinating thought experiment is the &amp;ldquo;inverted spectrum&amp;rdquo; theory. I don&amp;rsquo;t buy into it but I think it&amp;rsquo;s worth reading about. See &lt;a href=&#34;https://plato.stanford.edu/entries/qualia-inverted/&#34;&gt;Qualia inverted (Stanford)&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    <item>
      <title>What&#39;s &#34;funny&#34;? The missing piece of a critical elliptic vuln</title>
      <link>https://arnaudbrousseau.com/notes/funny-elliptic-vuln.html</link>
      <pubDate>Fri, 14 Aug 2026 09:03:56 -0500</pubDate>
      <guid>https://arnaudbrousseau.com/notes/funny-elliptic-vuln.html</guid>
      <description>&lt;script&gt; MathJax = { loader: { load: [&#39;input/asciimath&#39;, &#39;output/chtml&#39;] } }; &lt;/script&gt;
&lt;script type=&#34;text/javascript&#34; src=&#34;https://arnaudbrousseau.com/js/mathjax/tex-chtml.js&#34; id=&#34;MathJax-script&#34; async&gt;&lt;/script&gt;
&lt;h2 id=&#34;tldr&#34;&gt;TL;DR&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&#34;https://github.com/indutny/elliptic/security/advisories/GHSA-vjh7-7g9h-fjfh&#34;&gt;GHSA-vjh7-7g9h-fjfh&lt;/a&gt; advisory for &lt;a href=&#34;https://github.com/indutny/elliptic&#34;&gt;&lt;code&gt;elliptic&lt;/code&gt;&lt;/a&gt; suggests that for any previously signed message, an attacker can construct a second message that forces nonce reuse and enables ECDSA private key recovery.&lt;/p&gt;
&lt;p&gt;Below I&amp;rsquo;m investigating this claim by reverse-engineering the &lt;code&gt;funny&lt;/code&gt; function included in the GHSA &amp;ldquo;full attack&amp;rdquo; snippet, which constructs this second message.&lt;/p&gt;
&lt;p&gt;The trick turns out to be related to sign symmetry in BN serialization (it&amp;rsquo;s the root cause of the vuln, see &lt;a href=&#34;https://github.com/indutny/elliptic/commit/04cb6f54ce552b3ebde6be06d6050419e1c7333e&#34;&gt;the patch&lt;/a&gt;). However, constructing a second message to trigger a nonce reuse requires more than that: &lt;code&gt;truncateToN&lt;/code&gt;, an internal function, needs to be reversed. For a standard 256-bit digest I&amp;rsquo;ll show that a second message exists only for a subset of digests: 1-in-16 digests for secp256k1, and 1-in-8 digests for ed25519. Goes without saying: still very bad. Please upgrade &lt;code&gt;elliptic&lt;/code&gt; if you haven&amp;rsquo;t, it&amp;rsquo;s been well over a year!&lt;/p&gt;
&lt;h2 id=&#34;what-is-this-ghsa-about&#34;&gt;What is this GHSA about&lt;/h2&gt;
&lt;p&gt;In February 2025, the &lt;a href=&#34;https://github.com/indutny/elliptic&#34;&gt;&lt;code&gt;elliptic&lt;/code&gt;&lt;/a&gt; package disclosed a critical vulnerability related to nonce generation during signing: &lt;a href=&#34;https://github.com/indutny/elliptic/security/advisories/GHSA-vjh7-7g9h-fjfh&#34;&gt;GHSA-vjh7-7g9h-fjfh&lt;/a&gt;. The advisory describes a bug which leads to two distinct messages sharing the same nonce. This &amp;ldquo;k reuse&amp;rdquo; enables private key recovery with simple algebra: from two signatures sharing the same nonce, it&amp;rsquo;s trivial to recover the private key. ECDSA signatures are produced with the following:&lt;/p&gt;
&lt;p&gt;`s = k^{-1}(z + rd) mod n`&lt;/p&gt;
&lt;p&gt;where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;z = message hash&lt;/li&gt;
&lt;li&gt;d = private key&lt;/li&gt;
&lt;li&gt;k = nonce&lt;/li&gt;
&lt;li&gt;r = x coordinate of kG&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If two messages `z_1` and `z_2` are signed with the same nonce k, they share the same r value and satisfy:&lt;/p&gt;
&lt;p&gt;`s_1 = k^{-1}(z_1 + rd)` and `s_2 = k^{-1}(z_2 + rd)`&lt;/p&gt;
&lt;p&gt;Subtracting the two equations gives:&lt;/p&gt;
&lt;p&gt;`s_1 - s_2 = k^{-1}(z_1 - z_2)`&lt;/p&gt;
&lt;p&gt;Hence we can compute k, assuming `(s_1 - s_2)` is invertible modulo n:&lt;/p&gt;
&lt;p&gt;`k = (z_1 - z_2)/(s_1 - s_2) mod n`&lt;/p&gt;
&lt;p&gt;And then we can compute the private key:&lt;/p&gt;
&lt;p&gt;`d = (s_1 k - z_1)/r mod n`&lt;/p&gt;
&lt;p&gt;Thus a single nonce reuse leaks the private key; game over 💀&lt;/p&gt;
&lt;h2 id=&#34;a-funny-hook&#34;&gt;A &lt;code&gt;funny&lt;/code&gt; hook&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&#34;https://github.com/indutny/elliptic/security/advisories/GHSA-vjh7-7g9h-fjfh&#34;&gt;GHSA advisory&lt;/a&gt; states that &lt;em&gt;&amp;ldquo;a message can be constructed for any already known message/signature pair, meaning that the attack needs only a single malicious message being signed for a full key extraction&amp;rdquo;&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;In other words, given historical signatures, an attacker can compute a malicious message which, if signed, will lead to nonce reuse and private key recovery. Crazy. In the advisory details there is abridged code for a &amp;ldquo;full attack&amp;rdquo;. The &lt;code&gt;funny&lt;/code&gt; function on line 6 caught my eye&amp;hellip;&lt;/p&gt;
&lt;pre class=&#34;brush:js; highlight: [6,6]&#34;&gt;
// Any message, e.g. previously known signature
const msg0 = crypto.getRandomValues(new Uint8Array(32))
const sig0 = ec.sign(msg0, privateKey)

// Attack
const msg1 = funny(msg0) // this is a string here, but can also be of other non-Uint8Array types
const sig1 = ec.sign(msg1, privateKey)
&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;funny(msg0)&lt;/code&gt; function here isn&amp;rsquo;t defined in the GHSA &amp;ldquo;on purpose&amp;rdquo;. I couldn&amp;rsquo;t help but wonder: what&amp;rsquo;s the shape of this &lt;code&gt;funny&lt;/code&gt; function? Is it easy to implement? Let&amp;rsquo;s find out.&lt;/p&gt;
&lt;h2 id=&#34;the-core-issue-bn-serialization&#34;&gt;The core issue: BN serialization&lt;/h2&gt;
&lt;p&gt;Before we jump into writing the core of this &lt;code&gt;funny&lt;/code&gt; function let&amp;rsquo;s review the details of the vulnerability and what broke exactly. This will help us design the &lt;code&gt;funny&lt;/code&gt; function later on.&lt;/p&gt;
&lt;p&gt;At a high level, &lt;code&gt;elliptic&lt;/code&gt;&amp;rsquo;s vulnerable signing code (&lt;a href=&#34;https://github.com/indutny/elliptic/blob/3e46a48fdd2ef2f89593e5e058d85530578c9761/lib/elliptic/ec/index.js#L100-L107&#34;&gt;link&lt;/a&gt;) performs the following transformations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A message (string) is truncated with &lt;code&gt;truncateToN(...)&lt;/code&gt; to yield a big number for signing (BN).&lt;/li&gt;
&lt;li&gt;The resulting BN is serialized with &lt;code&gt;toArray(&#39;be&#39;, 32)&lt;/code&gt; to yield the base bytes for nonce generation&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The vulnerability exists because this pipeline is not injective: distinct messages can eventually produce identical nonce inputs.&lt;/p&gt;
&lt;p&gt;When first reading the advisory, it is tempting to focus on the &lt;code&gt;truncateToN()&lt;/code&gt; function. Much of the complexity lives there: message parsing, bit-length calculations, shifting, and reduction modulo the curve order.&lt;/p&gt;
&lt;p&gt;I initially focused on constructing collisions inside &lt;code&gt;truncateToN()&lt;/code&gt;. Seems reasonable: if the same message yields the same BN after truncation logic, it follows that we&amp;rsquo;ll see the same nonce as well!&lt;/p&gt;
&lt;p&gt;If an attacker wants to target an existing signature (for message &lt;code&gt;m&lt;/code&gt;), perhaps they need to find another message &lt;code&gt;m&#39;&lt;/code&gt; such that &lt;code&gt;truncateToN(m&#39;) = truncateToN(m)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Turns out this is the wrong mental model: the result of &lt;code&gt;truncateToN&lt;/code&gt; (BN) is used not only for nonce generation but also as an input for signing. In other words: if we find &lt;code&gt;m&#39;&lt;/code&gt; such that &lt;code&gt;truncateToN(m&#39;)&lt;/code&gt; equals &lt;code&gt;truncateToN(m)&lt;/code&gt;, then the two signatures will be &lt;em&gt;exactly&lt;/em&gt; the same: same &lt;code&gt;r&lt;/code&gt; component, same &lt;code&gt;s&lt;/code&gt; component. That&amp;rsquo;s because the message-to-be-signed (a BN) is the same. This will not lead to a private key leak: we saw in the first section that private key extraction requires 2 distinct signatures to work: `s_1` and `s_2`. This determinism is a feature, not a bug; we&amp;rsquo;re simply seeing message collision (distinct messages, same signatures).&lt;/p&gt;
&lt;p&gt;The real issue is later in the pipeline and it&amp;rsquo;s related to BN serialization. After truncation, the library serializes the resulting BN with:&lt;/p&gt;
&lt;pre class=&#34;brush:js&#34;&gt;
var nonce = msg.toArray(&#39;be&#39;, 32);
&lt;/pre&gt;
&lt;p&gt;The subtle but critical detail is that BN serialization to a fixed-length byte array drops sign information. &lt;strong&gt;This is the core of the vulnerability&lt;/strong&gt;. For example:&lt;/p&gt;
&lt;pre class=&#34;brush:js&#34;&gt;
const n = new BN(
  &#34;c1c7740ee5c0f246640f4be0934024e6e1536cf90f970d7bd4c1461b60af11dc&#34;,
  16
);

const negN = n.neg();

n.toArray(&#39;be&#39;, 32) === negN.toArray(&#39;be&#39;, 32);
&lt;/pre&gt;
&lt;p&gt;Both serialize to the same 32-byte array ⚠️&lt;/p&gt;
&lt;p&gt;If you look at the &lt;a href=&#34;https://github.com/indutny/elliptic/commit/04cb6f54ce552b3ebde6be06d6050419e1c7333e&#34;&gt;commit which fixes the vulnerability&lt;/a&gt;, bingo: it&amp;rsquo;s all about preventing negative numbers from being signed to prevent potential nonce reuse issues.&lt;/p&gt;
&lt;h2 id=&#34;what-our-funny-function-does&#34;&gt;What our &lt;code&gt;funny&lt;/code&gt; function does&lt;/h2&gt;
&lt;p&gt;The BN serialization sign-drop is at the core of the vuln. If a message truncates to some value &lt;code&gt;x&lt;/code&gt;, and we can craft a second message that truncates to &lt;code&gt;-x&lt;/code&gt;, then the two serialize to the &lt;em&gt;same&lt;/em&gt; 32 bytes. Same nonce, but different input messages: that&amp;rsquo;s the combo that&amp;rsquo;ll get your private key leaked.&lt;/p&gt;
&lt;p&gt;So the &lt;code&gt;funny&lt;/code&gt; function has one job: given &lt;code&gt;msg0&lt;/code&gt; (which truncates to some &lt;code&gt;x&lt;/code&gt;), produce a &lt;code&gt;msg1&lt;/code&gt; that truncates to &lt;code&gt;-x&lt;/code&gt;. Visually speaking:&lt;/p&gt;
&lt;img src=&#34;https://arnaudbrousseau.com/img/funny-inner-workings.png&#34; alt=&#34;Inner workings of funny function&#34; style=&#34;max-width: 500px&#34; /&gt;
&lt;p&gt;The rest of this post is about whether the dashed arrow can always work. Spoiler: nope!&lt;/p&gt;
&lt;h2 id=&#34;inverting-truncateton-not-always-possible&#34;&gt;Inverting &lt;code&gt;truncateToN&lt;/code&gt;: not always possible&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s look at what we&amp;rsquo;re inverting. The full routine is &lt;a href=&#34;https://github.com/indutny/elliptic/blob/b8a7edd61a0d9bddd0bbf3436a4b476401edbe20/lib/elliptic/ec/index.js#L81-L108&#34;&gt;here&lt;/a&gt; but it boils down to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Measure the input message&amp;rsquo;s &lt;strong&gt;synthetic byte length&lt;/strong&gt; (let&amp;rsquo;s call it &lt;code&gt;L&lt;/code&gt; going forward): for strings this is derived from their length, which includes any &lt;code&gt;&amp;quot;-&amp;quot;&lt;/code&gt; sign, adding 1, and dividing by two (using &lt;code&gt;floor()&lt;/code&gt;). For example &lt;code&gt;-c0ffee&lt;/code&gt; has 7 characters, which means a synthetic byte length of &lt;code&gt;floor((7+1)/2) = 4&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Right-shift the value by `∂ = 8L - b` (where &lt;code&gt;b&lt;/code&gt; is the curve order&amp;rsquo;s bit length), if that delta is strictly positive.&lt;/li&gt;
&lt;li&gt;If the value is still more than the curve order after the shift, subtract it (this never happens for negative numbers).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To build a &lt;code&gt;msg1&lt;/code&gt; that truncates to &lt;code&gt;-x&lt;/code&gt;, we&amp;rsquo;d left-shift &lt;code&gt;-x&lt;/code&gt; back up by &lt;code&gt;∂&lt;/code&gt;. But &lt;code&gt;∂&lt;/code&gt; depends on the &lt;em&gt;synthetic bit length of the result&lt;/em&gt;, which depends on the string we&amp;rsquo;re constructing. That&amp;rsquo;s a circular dependency. If you fix the target length and work it through (I did, for a range of lengths), a pattern emerges: &lt;strong&gt;there&amp;rsquo;s a ceiling on how large &lt;code&gt;|x|&lt;/code&gt; can be and still have a pre-image.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s what this looks like for messages of different lengths. We take ed25519 as an example, where the curve order has 253 bits (secp256k1 is 256 bits, which makes the table a bit less interesting.)&lt;/p&gt;
&lt;style&gt;
table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    font-size: 0.95rem;
}

table th {
    border-bottom: 2px solid #ddd;
    padding: 0.75rem 1rem;
    text-align: center;
    white-space: nowrap;
}

table td {
    padding: 0.65rem 1rem;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
}

table tbody tr:nth-child(even) {
    background: rgba(127, 127, 127, 0.06);
}

table tbody tr:hover {
    background: rgba(127, 127, 127, 0.12);
}

table td:nth-child(1),
table td:nth-child(2),
table td:nth-child(5) {
    font-weight: 600;
}

table td:nth-child(3),
table td:nth-child(4),
table td:nth-child(6) {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

table code {
    background: none;
    padding: 0;
}
&lt;/style&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Synthetic byte length &lt;code&gt;L&lt;/code&gt;&lt;/th&gt;
&lt;th style=&#34;text-align:center&#34;&gt;Hex digits&lt;/th&gt;
&lt;th style=&#34;text-align:center&#34;&gt;Range for |msg1|&lt;/th&gt;
&lt;th style=&#34;text-align:center&#34;&gt;δ&lt;/th&gt;
&lt;th style=&#34;text-align:center&#34;&gt;Range for |x|&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;[57,58]&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;[2^220, 2^228)&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;-21 (no shift)&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;[2^220, 2^228)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;[59,60]&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;[2^228, 2^236)&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;-13 (no shift)&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;[2^228, 2^236)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;[61,62]&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;[2^236, 2^244)&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;-5 (no shift)&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;[2^236, 2^244)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;32&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;[63,64]&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;[2^244, 2^252)&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;3&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;[2^241, 2^249)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;33&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;[65,66]&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;[2^252, 2^260)&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;11&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;[2^241, 2^249)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;34&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;[67,68]&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;[2^260, 2^268)&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;19&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;[2^241, 2^249)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;In the table above, we look at increasing byte lengths for a message, and look at the numerical ranges of the input (&lt;code&gt;msg1&lt;/code&gt;), the computed delta given &lt;code&gt;b=253&lt;/code&gt; (&lt;code&gt;∂ = 8L-253&lt;/code&gt;), and the resulting range for &lt;code&gt;|x|&lt;/code&gt;. It&amp;rsquo;s clear that &lt;code&gt;|x|&lt;/code&gt; caps out at &lt;code&gt;2^249&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Now let&amp;rsquo;s figure out why and prove it.&lt;/p&gt;
&lt;h2 id=&#34;a-small-proof-where-funny-runs-out-of-room&#34;&gt;A small proof: where &lt;code&gt;funny&lt;/code&gt; runs out of room&lt;/h2&gt;
&lt;p&gt;What we want to prove:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A negative number `-x` has a pre-image under &lt;code&gt;truncateToN&lt;/code&gt; &lt;strong&gt;if and only if&lt;/strong&gt; `|x| &amp;lt; 2^{b-4}`, where `b` is the curve order&amp;rsquo;s bit length&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Recall what &lt;code&gt;truncateToN&lt;/code&gt; does on a negative hex string &lt;code&gt;s = &amp;quot;-...&amp;quot;&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It reads a &lt;strong&gt;synthetic byte length&lt;/strong&gt; `L` from the character count: `L = floor((\text{len}(s) + 1)/2)`, where `\text{len}(s)` counts the leading &lt;code&gt;&amp;quot;-&amp;quot;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;It parses &lt;code&gt;s&lt;/code&gt; as a BN with &lt;code&gt;new BN(s, 16)&lt;/code&gt; (let&amp;rsquo;s call this number &lt;code&gt;M&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;It right-shifts &lt;code&gt;M&lt;/code&gt; by `∂ = 8L - b`&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Let&amp;rsquo;s start with a simple fact: a negative string &lt;code&gt;s&lt;/code&gt; of synthetic byte length &lt;code&gt;L&lt;/code&gt; has at most &lt;code&gt;2L-1&lt;/code&gt; hex digits of amplitude. So `|M| &amp;lt; 16^{2L-1}`, or `|M| &amp;lt; 2^{8L-4}` (&amp;ldquo;fact 1&amp;rdquo;)&lt;/p&gt;
&lt;p&gt;Given an input string and its resulting &lt;code&gt;|M|&lt;/code&gt;, two cases to consider.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;No shift (&lt;code&gt;∂ ≤ 0&lt;/code&gt;, which means &lt;code&gt;8L ≤ b&lt;/code&gt;):&lt;/strong&gt; &lt;code&gt;M&lt;/code&gt; passes through &amp;ldquo;untouched&amp;rdquo;.&lt;br&gt;
`|truncateToN(s)| = M` and we have `|truncateToN(s)| &amp;lt;= 2^{8L-4}` (by fact 1).&lt;br&gt;
Given &lt;code&gt;8L ≤ b&lt;/code&gt;:  `|truncateToN(s)| &amp;lt;= 2^{b-4}`.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Shift (&lt;code&gt;∂ &amp;gt; 0&lt;/code&gt;, which means &lt;code&gt;8L &amp;gt; b&lt;/code&gt;):&lt;/strong&gt; &lt;code&gt;M&lt;/code&gt; is right-shifted by `∂ = 8L - b`. Let&amp;rsquo;s define &lt;code&gt;M&#39;&lt;/code&gt; as the result of this right-shift: &lt;code&gt;M&#39; = M &amp;gt;&amp;gt; ∂&lt;/code&gt;. A right-shift removes bits, which means the magnitude of &lt;code&gt;M&#39;&lt;/code&gt; is predictable: we have `|M&#39;| &amp;lt; 2^{8L-4} / 2^{8L-b}`.&lt;br&gt;
Simplifying the upper bound: `2^{8L-4} / 2^{8L-b} = 2^{(8L-4)-(8L-b)} = 2^{b-4}`.&lt;br&gt;
&lt;code&gt;M&#39;&lt;/code&gt; is the result returned by &lt;code&gt;truncateToN&lt;/code&gt;, so we have shown `|truncateToN(s)| &amp;lt; 2^{b-4}`.&lt;/p&gt;
&lt;p&gt;In both cases we&amp;rsquo;ve proven `|truncateToN(s)| &amp;lt; 2^{b-4}`. We&amp;rsquo;ve established `2^{b-4}` as our upper bound, and proven that no pre-image exists past that.&lt;/p&gt;
&lt;p&gt;Now let&amp;rsquo;s quickly prove that a pre-image exists when `|truncateToN(s)| &amp;lt; 2^{b-4}`.&lt;/p&gt;
&lt;p&gt;To write `|truncateToN(s)|` in hex we need at most `b/4 - 1` hex digits (`16^{b/4-1} = 2^{b-4}`). Now let&amp;rsquo;s write `|truncateToN(s)|` in hex and prepend a minus sign, and call the result &lt;code&gt;s&lt;/code&gt;. Its length is at most `b/4` hex digits, so `L` is at most `floor((b/4 + 1)/2) = floor((b+4)/8) &amp;lt;= b/8`. `L &amp;lt;= b/8` implies `8L &amp;lt;= b`, and `∂ &amp;lt;= 0` by definition of `∂`. With no shift, `truncateToN` just parses the integer. So our constructed &lt;code&gt;s&lt;/code&gt; is a valid pre-image.&lt;/p&gt;
&lt;p&gt;Together: a negative integer &lt;code&gt;-x&lt;/code&gt; has a pre-image exactly on `(0, 2^{b-4})` ∎&lt;/p&gt;
&lt;p&gt;The above is the formal version of the intuition that &lt;em&gt;&amp;ldquo;a longer hex string doesn&amp;rsquo;t help.&amp;quot;&lt;/em&gt; Every extra synthetic byte &amp;ldquo;buys&amp;rdquo; 8 bits of representable magnitude but &amp;ldquo;costs&amp;rdquo; 8 bits of shift. This is what we observed in the table. They&amp;rsquo;re the same quantity, so they cancel each other out: no string, however long, results in a single bit above &lt;code&gt;2^{b-4}&lt;/code&gt;. Now we know why!&lt;/p&gt;
&lt;h2 id=&#34;exploitable-ranges-for-standard-digests&#34;&gt;Exploitable ranges for standard digests&lt;/h2&gt;
&lt;p&gt;We&amp;rsquo;ve shown that given a target &lt;code&gt;-x&lt;/code&gt;, a pre-image exists if and only if &lt;code&gt;x&lt;/code&gt; lands in the reachable window `(0, 2^{b-4})`. The next question to ask is: &lt;strong&gt;which original messages are targetable?&lt;/strong&gt; A signature message is exploitable only if its own truncated value &lt;code&gt;x&lt;/code&gt; lands in `(0, 2^{b-4})`. We need to know which digests produce such an &lt;code&gt;x&lt;/code&gt; to deduce the exploitable ranges.&lt;/p&gt;
&lt;p&gt;Luckily the function to invert is the same: &lt;code&gt;truncateToN&lt;/code&gt;. We now apply it to a &lt;em&gt;positive&lt;/em&gt; message. The extra wrinkle compared to negative messages: the subtraction step.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Two disjoint bands for ed25519&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s use ed25519 here (so &lt;code&gt;b = 253&lt;/code&gt;). For a standard 32-byte digest, &lt;code&gt;L&lt;/code&gt; is 32, which means &lt;code&gt;∂ = 8*32 - 253 = 3&lt;/code&gt;. `truncateToN` computes `floor(\text{msg}/8)` (right-shift by 3 is a division by 8), then subtracts &lt;code&gt;N&lt;/code&gt; if the result still exceeds &lt;code&gt;N&lt;/code&gt;. A digest is exploitable when that value lands in `(0, 2^{249})` (see proof above), and there are &lt;strong&gt;two&lt;/strong&gt; separate ways to get there:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If `msg &amp;lt; 2^{252}`, then `floor({msg}/8) &amp;lt; 2^{249}` already; the subtraction branch never fires, and we land in range directly. This band is `(0, 2^{252})`, trivially.&lt;/li&gt;
&lt;li&gt;If `floor({msg}/8)` overshoots the curve order, the subtraction pulls it back down into range. That happens for &lt;code&gt;msg&lt;/code&gt; in `(8n, 8n + 2^{252})`, our second band of width &lt;code&gt;2^{252}&lt;/code&gt;, sitting up near &lt;code&gt;2^{255}&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Only one band for secp256k1&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The same construction on secp256k1 yields &lt;code&gt;∂ = 0&lt;/code&gt; (standard digests have 64 chars, which matches the curve order&amp;rsquo;s 256-bit length). The result of &lt;code&gt;truncateToN&lt;/code&gt; simplifies to either &lt;code&gt;msg&lt;/code&gt;, or &lt;code&gt;msg-N&lt;/code&gt; when &lt;code&gt;msg &amp;gt; N&lt;/code&gt;. The first &amp;ldquo;low&amp;rdquo; band we found survives: `msg &amp;lt; 2^{252}` lands in range. But the second band would sit &lt;em&gt;above&lt;/em&gt; the digest space. A 256-bit digest can&amp;rsquo;t exceed `2^{256}`, so the second band doesn&amp;rsquo;t exist.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Likelihood of a vulnerable signature&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ve done a lot of hard work, now it&amp;rsquo;s smooth sailing. Just need to count the bands!&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For ed25519, two disjoint bands each of width `2^{252}` sit inside the `2^{256}` digest space: `P_{\text{vulnerable}} = (2*2^{252})/2^256 = 1/8 = 12.5%`&lt;/li&gt;
&lt;li&gt;For secp256k1, only one band: `P_{\text{vulnerable}} = 2^{252}/2^256 = 1/16 = 6.25%`&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So the bottom line, for a standard 256-bit digest, &lt;strong&gt;only a portion of pre-existing signatures are exploitable by our &lt;code&gt;funny&lt;/code&gt; function: &lt;code&gt;6.25%&lt;/code&gt; for secp256k1, &lt;code&gt;12.5%&lt;/code&gt; for ed25519&lt;/strong&gt;. To be clear, that is &lt;em&gt;catastrophically&lt;/em&gt; high. A one-in-sixteen chance of full private-key recovery per signature is not a chance worth taking. But it contradicts the GHSA&amp;rsquo;s claim that &amp;ldquo;a message can be constructed for any already known message/signature pair&amp;rdquo;.&lt;/p&gt;
&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Reading &lt;a href=&#34;https://github.com/indutny/elliptic/security/advisories/GHSA-vjh7-7g9h-fjfh&#34;&gt;GHSA-vjh7-7g9h-fjfh&lt;/a&gt; got me curious: what is this &lt;code&gt;funny()&lt;/code&gt; function exactly? Months later, here&amp;rsquo;s what the reverse-engineering turned up:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;My first instinct was to hunt for collisions inside &lt;code&gt;truncateToN()&lt;/code&gt;, where most of the complexity lives. I was wrong: the vulnerability comes from a loss of injectivity &lt;em&gt;later&lt;/em&gt;, when &lt;code&gt;toArray&lt;/code&gt; discards sign information.&lt;/li&gt;
&lt;li&gt;I was not able to verify the GHSA claim that there exists a &lt;code&gt;funny&lt;/code&gt; function which computes a vulnerable message for any pre-existing signature. Some message ranges are out of reach with the construction above. For a standard 256 bit digest, there&amp;rsquo;s a 6.25% chance (for secp256k1) or 12.5% chance (for ed25519) that our &lt;code&gt;funny&lt;/code&gt; candidate works. If you come across other &lt;code&gt;funny&lt;/code&gt; tricks to reach the remaining ranges, &lt;a href=&#34;https://x.com/arnaudbrousseau&#34;&gt;let me know&lt;/a&gt;!&lt;/li&gt;
&lt;li&gt;Even with unreachable ranges this vulnerability is still critical! It&amp;rsquo;s still bad bad bad. Please upgrade if you haven&amp;rsquo;t! (I really hope you have, it&amp;rsquo;s been well over a year!)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Thanks for reading, you&amp;rsquo;re a beast for making it this far!&lt;/p&gt;
&lt;h2 id=&#34;reproducibility-and-source-code&#34;&gt;Reproducibility and source code&lt;/h2&gt;
&lt;p&gt;The candidate constructions and reachability tests discussed in this post are available in the accompanying repository: &lt;a href=&#34;https://github.com/ArnaudBrousseau/funny-elliptic-vuln&#34;&gt;&lt;code&gt;funny-elliptic-vuln&lt;/code&gt;&lt;/a&gt;. The tests exercise the sign-symmetry construction across the reachable and unreachable ranges described above. If you find a construction that reaches the remaining ranges, I&amp;rsquo;d be very interested to hear about it. Please &lt;a href=&#34;https://x.com/arnaudbrousseau&#34;&gt;reach out&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Hacking Cryptography</title>
      <link>https://arnaudbrousseau.com/notes/hacking-cryptography.html</link>
      <pubDate>Sun, 12 Oct 2025 16:44:39 -0500</pubDate>
      <guid>https://arnaudbrousseau.com/notes/hacking-cryptography.html</guid>
      <description>&lt;script&gt; MathJax = { loader: { load: [&#39;input/asciimath&#39;, &#39;output/chtml&#39;] } }; &lt;/script&gt;
&lt;script type=&#34;text/javascript&#34; src=&#34;https://arnaudbrousseau.com/js/mathjax/tex-chtml.js&#34; id=&#34;MathJax-script&#34; async&gt;&lt;/script&gt;
&lt;p&gt;&lt;a href=&#34;https://www.manning.com/books/hacking-cryptography&#34;&gt;Hacking Cryptography&lt;/a&gt; is a book I pre-ordered in 2023. A physical copy was shipped to me in March earlier this year, and I finished reading it over the summer.&lt;/p&gt;
&lt;p&gt;I highly recommend picking up a copy if you work with cryptographic systems or concepts. I didn&amp;rsquo;t expect to learn much because I&amp;rsquo;ve read a few books on cryptography already (&lt;a href=&#34;https://www.schneier.com/books/cryptography-engineering/&#34;&gt;Cryptography Engineering&lt;/a&gt;, &lt;a href=&#34;https://www.amazon.com/dp/1593278268&#34;&gt;Serious Cryptography&lt;/a&gt;, &lt;a href=&#34;https://www.manning.com/books/real-world-cryptography&#34;&gt;Real-World Cryptography&lt;/a&gt;), but this book made a few things &amp;ldquo;click&amp;rdquo; for me. Probably because some things only truly click after you&amp;rsquo;ve seen them a few times, from different angles.&lt;/p&gt;
&lt;p&gt;I think this book&amp;rsquo;s &amp;ldquo;angle&amp;rdquo; has something to offer to everyone. I was impressed by the fearless &amp;ldquo;end-to-end&amp;rdquo; approach: each chapter explains important concepts and goes on to show a real exploit, implemented fully (in Golang, a language that is a bit verbose but very easy to read). It arms you with knowledge (and &lt;a href=&#34;https://github.com/krkhan/crypto-impl-exploit&#34;&gt;code&lt;/a&gt;!) that can be used to exploit real-world systems. Usually, authors shy away from showing full exploits or from the details, watering down the explanation for educational purposes. Not here! I love the unapologetic stance: broken crypto implementations laid bare and exploited, chapter after chapter. It&amp;rsquo;s sitting at the edge of &amp;ldquo;white hat&amp;rdquo; and &amp;ldquo;black hat&amp;rdquo; material.&lt;/p&gt;
&lt;p&gt;Chapters are structured with concept explainers first (useful to jog your memory if you&amp;rsquo;ve seen these before, or lay down the foundations if you haven&amp;rsquo;t), then exploits. After a few chapters you start thinking before the exploit comes, as you&amp;rsquo;re reading the concepts: &amp;ldquo;what could go wrong&amp;rdquo;? &amp;ldquo;What &lt;strong&gt;will&lt;/strong&gt; go wrong this time around&amp;rdquo;? Below are some moments of clarity which feel valuable enough to write about.&lt;/p&gt;
&lt;h1 id=&#34;types-of-entropy-sources&#34;&gt;Types of entropy sources&lt;/h1&gt;
&lt;p&gt;Have you ever wondered where &amp;ldquo;true&amp;rdquo; entropy comes from and how it can be digitized? Me neither—but this book answered that question anyway. I&amp;rsquo;ve used hardware TRNGs (typically USB-based) for key ceremonies but never researched how they work. The book explains this in detail.&lt;/p&gt;
&lt;p&gt;True Random Number Generators (TRNGs) sample physical phenomena which must be random by nature. A well-known example of a &amp;ldquo;true&amp;rdquo; random phenomenon is radioactive decay: each atom has a random probability to decay associated with it, and radioactive decay for a large group of atoms follows a well-known exponential decay curve. Unfortunately radioactive decay is expensive to sample and use safely, hence hard to produce digital entropy from.&lt;/p&gt;
&lt;p&gt;Other known (but flawed!) sources of entropy:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Atmospheric noise is a cheap source of entropy because radio receivers are easy to build. Unfortunately they&amp;rsquo;re easy to fool: an attacker can influence the output with electromagnetic interference.&lt;/li&gt;
&lt;li&gt;Measuring CPU clock drift and using that as a source of entropy is also cheap but unfortunately that&amp;rsquo;s not trivial to use safely because attackers can influence or predict the output easily.&lt;/li&gt;
&lt;li&gt;The avalanche or &lt;a href=&#34;https://en.wikipedia.org/wiki/Zener_effect&#34;&gt;Zener effect&lt;/a&gt; in diodes is a commonly used method because it&amp;rsquo;s cheap, but is subject to interference and doesn&amp;rsquo;t have a proper underlying physical model to assess the health of the TRNG hardware. There are large variations from device to device, and manufacturers do not build diodes with this use case in mind. Quite the opposite: in the context of normal operations, the avalanche effect is undesirable, and manufacturers work to reduce or eliminate it.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The book concludes this chapter by talking about MEM (Modular Entropy Multiplication), a method invented in the late 1990s. It works by amplifying thermal noise based on simple rules. The voltage has a target range (`V_{min}`, `V_{max}`), and the TRNG circuit doubles it if less than half the target range, or adds `V-V_{max}` if more than half. If V exceeds `V_{max}`, it wraps around to `V_{min}`. This method is resistant to electromagnetic interference, and comes with a physical model for health checks. Beautiful, simple, open-source hardware TRNG design. See the &lt;a href=&#34;https://github.com/waywardgeek/infnoise&#34;&gt;Infinite No-ise TRNG design&lt;/a&gt; and the associated &lt;a href=&#34;https://github.com/alwynallan/redoubler&#34;&gt;REDOUBLER&lt;/a&gt;.&lt;/p&gt;
&lt;h1 id=&#34;randomness-extractors&#34;&gt;Randomness extractors&lt;/h1&gt;
&lt;p&gt;Something I didn&amp;rsquo;t know: randomness from natural sources is generally not high-entropy enough. This was new to me — and fascinating to learn. The book mentions that &lt;a href=&#34;https://en.wikipedia.org/wiki/Randomness_extractor&#34;&gt;&lt;strong&gt;randomness extractors&lt;/strong&gt;&lt;/a&gt; have to be used on top of TRNGs. Another interesting takeaway: randomness extractors can be remarkably simple.&lt;/p&gt;
&lt;p&gt;The example given in the book is the following algorithm: if two successive bits (of a random input stream) match, generate no output, and if they&amp;rsquo;re different, output the first bit only. The output stream will be &amp;ldquo;denser&amp;rdquo; than the input bit stream, hence higher in entropy.&lt;/p&gt;
&lt;h1 id=&#34;measuring-entropy-requires-a-physical-model&#34;&gt;Measuring entropy requires a physical model&lt;/h1&gt;
&lt;p&gt;Entropy is a measure of randomness. In cryptography, randomness is fundamental. Thus, if you work on very sensitive cryptography (offline key generation ceremonies are a perfect example) you&amp;rsquo;ll want to use a TRNG. But how do you measure whether what you get out is &amp;ldquo;random enough&amp;rdquo;? How do you know when your device is too old or starts breaking down?&lt;/p&gt;
&lt;p&gt;The concept that was missing for me is the concept of measurement &lt;em&gt;against a physical model&lt;/em&gt;. A good TRNG will have theoretical foundations for why the physical phenomenon it uses is random, and the model should be able to predict the rate of entropy. The author frames this as a &amp;ldquo;health check&amp;rdquo; for TRNGs: because the physical world is messy and TRNGs are physical devices, it&amp;rsquo;s crucial to know when your TRNG starts malfunctioning. A physical model provides a baseline for measuring entropy — without it, you can’t know when a TRNG starts to fail.&lt;/p&gt;
&lt;p&gt;Another interesting fact is that not all TRNGs have an underlying physical model, hence they should be avoided for high-security use cases. For example: TRNGs based on the Zener effect in diodes, or noise in ring oscillators, have no underlying physical models for entropy. Radioactive decay, or MEM-based TRNGs do.&lt;/p&gt;
&lt;h1 id=&#34;csprngs-vs-prngs&#34;&gt;CSPRNGs vs. PRNGs&lt;/h1&gt;
&lt;p&gt;I&amp;rsquo;ve always known that some random number generators are better than others. If you want strong random numbers in Golang for example, never use &lt;code&gt;math/rand&lt;/code&gt;, always use &lt;code&gt;crypto/rand&lt;/code&gt;. But why? My prior mental model (loosely) was that &lt;code&gt;math/rand&lt;/code&gt; is fast but repeats a sequence of &amp;ldquo;random-looking&amp;rdquo; bytes, whereas &lt;code&gt;crypto/rand&lt;/code&gt; uses hardware randomness and therefore produces &amp;ldquo;truly random&amp;rdquo; byte sequences. I was wrong on multiple counts!&lt;/p&gt;
&lt;p&gt;First, a bit of definition: to be &lt;strong&gt;c&lt;/strong&gt;ryptographically &lt;strong&gt;s&lt;/strong&gt;ecure (and be a &lt;strong&gt;CS&lt;/strong&gt;PRNG), a PRNG should satisfy the following properties:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;An attacker should not be able to look at the output values and deduce that they came from a PRNG (as opposed to some random noise).&lt;/li&gt;
&lt;li&gt;An attacker should not be able to guess past values by looking at current (and future) output values. This is referred to as &lt;strong&gt;forward secrecy&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;An attacker should not be able to guess future values by looking at past output values. This is referred to as &lt;strong&gt;backward secrecy&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A useful example of a PRNG that is &lt;em&gt;not&lt;/em&gt; cryptographically secure is the &lt;a href=&#34;https://en.wikipedia.org/wiki/Linear_congruential_generator&#34;&gt;Linear Congruential Generator&lt;/a&gt; (LCG). Output values (&lt;code&gt;X&lt;/code&gt;) are generated from a seed with the formula:&lt;/p&gt;
&lt;p&gt;`X_{n+1} = (aX_n + c) mod m`&lt;/p&gt;
&lt;p&gt;(&lt;code&gt;m&lt;/code&gt; is the modulus, &lt;code&gt;a&lt;/code&gt; is the multiplier, &lt;code&gt;c&lt;/code&gt; is the increment)&lt;/p&gt;
&lt;p&gt;The book goes on to show the weakness: it&amp;rsquo;s possible to recover &lt;code&gt;m&lt;/code&gt;, &lt;code&gt;a&lt;/code&gt;, and &lt;code&gt;c&lt;/code&gt; by observing a series of output values. All it takes is a bit of linear algebra:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The modulus &lt;code&gt;m&lt;/code&gt; can be guessed by looking at GCD of &amp;ldquo;zeros&amp;rdquo; (numbers which are equal to 0 modulo &lt;code&gt;m&lt;/code&gt; by construction). These &amp;ldquo;zeros&amp;rdquo; are computed by looking at differences of output numbers from the LCG we want to attack. It takes a good amount of output numbers to &amp;ldquo;crack&amp;rdquo; the modulus (~1000 observations.)&lt;/li&gt;
&lt;li&gt;With the modulus in hand, recovering &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;c&lt;/code&gt; is trivial. &lt;code&gt;a&lt;/code&gt; can be recovered by looking at the difference between 2 output values and computing an inverse modulo &lt;code&gt;m&lt;/code&gt;, and recovering &lt;code&gt;c&lt;/code&gt; is a simple multiplication and subtraction from there.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you&amp;rsquo;re curious about the details, check out &lt;a href=&#34;https://github.com/krkhan/crypto-impl-exploit/tree/main/ch02/lcg/go/exploit_lcg&#34;&gt;&lt;code&gt;ch02/lcg/go/exploit_lcg&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Another insecure PRNG is described and exploited in the book: MT19937 (Mersenne-Twister). It&amp;rsquo;s a very interesting exploit because MT19937 is still the default PRNG in &lt;a href=&#34;https://docs.ruby-lang.org/en/master/Random.html&#34;&gt;Ruby&lt;/a&gt; and &lt;a href=&#34;https://docs.python.org/3/library/random.html&#34;&gt;Python&lt;/a&gt;. The exploit shows concrete code to clone an existing MT19937 and predict future values from observing a few output values. See the code &lt;a href=&#34;https://github.com/krkhan/crypto-impl-exploit/blob/main/ch03/mt19937/exploit_mt19937/exploit_mt19937.go&#34;&gt;here&lt;/a&gt;, it&amp;rsquo;s less than 50 lines total and shows, rather than tells, how insecure default PRNGs can be.&lt;/p&gt;
&lt;p&gt;So, looking back at my initial mental model: where was I wrong?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&amp;ldquo;Insecure&amp;rdquo; PRNGs do not repeat themselves predictably: they&amp;rsquo;re generally seeded with TRNGs. While they do repeat themselves (after a known &amp;ldquo;period&amp;rdquo;), the sequence itself is random every time the PRNG is initialized, because the seed is different every time. The reason they&amp;rsquo;re insecure isn&amp;rsquo;t the repetition, it&amp;rsquo;s the construction of the PRNG itself!&lt;/li&gt;
&lt;li&gt;CSPRNGs are seeded the same way as &amp;ldquo;insecure&amp;rdquo; PRNGs are, with TRNGs.&lt;/li&gt;
&lt;li&gt;CSPRNGs have finite periods, just like &amp;ldquo;insecure&amp;rdquo; PRNGs.&lt;/li&gt;
&lt;li&gt;The line between PRNG and CSPRNG isn’t black and white. It depends on how well the PRNG preserves forward and backward secrecy. Essentially, how securely it manages its internal state and next-value computation. If you can reverse them and recover a PRNG&amp;rsquo;s internal state, the CSPRNG is not cryptographically secure anymore: attackers can guess the following &amp;ldquo;random&amp;rdquo; values.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;dual_ec_bg-exploit&#34;&gt;&lt;code&gt;DUAL_EC_BG&lt;/code&gt; exploit&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;DUAL_EC_BG&lt;/code&gt; exploit is one that I&amp;rsquo;ve heard about many times in security and cryptography contexts to explain why the NSA cannot be trusted with cryptographic standards (for a good summary of everything that has happened over the years, look no further than &lt;a href=&#34;https://blog.cr.yp.to/20220805-nsa.html&#34;&gt;this DJB blog post&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Before reading this book, my understanding of the &lt;code&gt;DUAL_EC_BG&lt;/code&gt; exploit was that there was a secret that only the NSA knew which could be used as a trapdoor, but I didn&amp;rsquo;t know the specifics and I never bothered to look into it more deeply. Embarrassingly, I also didn&amp;rsquo;t know that &lt;code&gt;DUAL_EC_BG&lt;/code&gt; was a random number generator. I kind of assumed it was an encryption scheme? Unsure why. Turns out: &amp;ldquo;BG&amp;rdquo; stands for &amp;ldquo;Bit Generator&amp;rdquo;, and &lt;code&gt;DUAL_EC_BG&lt;/code&gt; was one of the &lt;a href=&#34;https://www.nist.gov/&#34;&gt;NIST&lt;/a&gt;-recommended CSPRNGs.&lt;/p&gt;
&lt;p&gt;This exploit is fascinating for a few reasons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The cryptographic design of &lt;code&gt;DUAL_EC_BG&lt;/code&gt; is solid, based on elliptic curve operations.&lt;/li&gt;
&lt;li&gt;The choice of the constants is where the problem lies: the backdoor is in the constant itself.&lt;/li&gt;
&lt;li&gt;There is no way to prove that the constant is backdoor&amp;rsquo;d unless you know the backdoor. Genius.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The design of &lt;code&gt;DUAL_EC_BG&lt;/code&gt; is elegant because it&amp;rsquo;s simple:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a seed is used as the RNG state (treated as a big number &lt;code&gt;n&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;to generate random bytes, perform the scalar multiplication of a well-known, constant point &lt;code&gt;Q&lt;/code&gt;: &lt;code&gt;nQ&lt;/code&gt;, then take the first 30 bytes of its x coordinate. These are your random output bytes.&lt;/li&gt;
&lt;li&gt;once the bytes are generated for a given &lt;code&gt;n&lt;/code&gt;, the state progresses: the next big number (&lt;code&gt;n+1&lt;/code&gt;) is the x coordinate of &lt;code&gt;nP&lt;/code&gt;, where &lt;code&gt;P&lt;/code&gt; is another well-known and constant point.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This looks secure on paper because both &amp;ldquo;next state&amp;rdquo; and &amp;ldquo;get random output&amp;rdquo; functions rely on elliptic curve point multiplication operations, which are hard to reverse. The exploit lies in the selection of &lt;code&gt;P&lt;/code&gt; and &lt;code&gt;Q&lt;/code&gt;: if these constants are related to each other such that &lt;code&gt;P&lt;/code&gt; is &lt;code&gt;dQ&lt;/code&gt; (where &lt;code&gt;d&lt;/code&gt; is the &amp;ldquo;secret&amp;rdquo; only known to the NSA), then the NSA can predict the &amp;ldquo;next&amp;rdquo; value by observing output values alone:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Remember the output values are the first 30 bytes of the x coordinate of &lt;code&gt;nQ&lt;/code&gt;. Recovering the &amp;ldquo;output point&amp;rdquo; &lt;code&gt;nQ&lt;/code&gt; from these 30 bytes alone requires trying all values for the 2 missing bytes (from &lt;code&gt;0x0000&lt;/code&gt; to &lt;code&gt;0xFFFF&lt;/code&gt;, ~65k values), and see which full x coordinate yields a point that lands on the underlying cryptographic curve.&lt;/li&gt;
&lt;li&gt;Once &lt;code&gt;nQ&lt;/code&gt;, the output point, is recovered, multiply it by &lt;code&gt;d&lt;/code&gt; (the hidden secret) and take the x coordinate of the resulting point to get the next state (&amp;ldquo;next state point&amp;rdquo; = &lt;code&gt;nP&lt;/code&gt; = &lt;code&gt;n*(dQ)&lt;/code&gt; = &lt;code&gt;d*(nQ)&lt;/code&gt; = &amp;ldquo;d times the recovered output point!&amp;quot;)&lt;/li&gt;
&lt;li&gt;And once you have the state &lt;code&gt;n&lt;/code&gt; of the RNG, it&amp;rsquo;s trivial to predict the next random values: compute &lt;code&gt;nQ&lt;/code&gt; and take the first 30 bytes of the x coordinate to get the next random bytes, then compute the next state, then the next random bytes, and so on. The RNG is successfully cloned.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There you have it — a CSPRNG that isn&amp;rsquo;t really &amp;ldquo;CS&amp;rdquo; if you believe the constants are backdoor&amp;rsquo;d.&lt;/p&gt;
&lt;h1 id=&#34;stream-ciphers&#34;&gt;Stream ciphers&lt;/h1&gt;
&lt;p&gt;What&amp;rsquo;s notable here is how the book introduces stream ciphers: they&amp;rsquo;re introduced as a clever solution to the limitation of One-Time Pads (OTPs), which is the only proven &amp;ldquo;perfectly secure&amp;rdquo; encryption scheme.&lt;/p&gt;
&lt;p&gt;The explanation goes like this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;OTPs require a key stream as long as the data being encrypted.&lt;/li&gt;
&lt;li&gt;Sharing a large amount of key stream is inconvenient and gets impossible as plaintext size grows (video files: GBs of data to encrypt; disk encryption: TBs of data!)&lt;/li&gt;
&lt;li&gt;The solution: share a single (short) seed, and use a CSPRNG to deterministically generate the same keystream during encryption (on the sender side) and decryption (on the receiver side)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As a reminder:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Encryption: plaintext XOR keystream =&amp;gt; ciphertext&lt;/li&gt;
&lt;li&gt;Decryption: ciphertext XOR keystream =&amp;gt; plaintext&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I thought this was a neat way to give intuition on why stream ciphers are designed this way; something clicked for me.&lt;/p&gt;
&lt;h1 id=&#34;cracking-wep-passwords-by-exploiting-rc4-bias&#34;&gt;Cracking WEP passwords by exploiting RC4 bias&lt;/h1&gt;
&lt;p&gt;RC4 is a popular stream cipher that was used by the first Wi-Fi security standard (WEP). Attackers can recover the Wi-Fi password by snooping on encrypted communications between genuine participants and then using the statistical biases in RC4 to crack the Wi-Fi network&amp;rsquo;s password.&lt;/p&gt;
&lt;p&gt;The attack is tricky and it&amp;rsquo;d be too long to explain it fully, but it&amp;rsquo;s done very well in the book. At a high-level, the &lt;a href=&#34;https://www.cs.cornell.edu/people/egs/615/rc4_ksaproc.pdf&#34;&gt;Fluhrer, Mantin, and Shamir (FMS) attack&lt;/a&gt; revealed a subtle bias in the RC4 key-scheduling algorithm. More specifically: if the first and second bytes of the RC4 seed are L and 255, respectively, then the Lth index of the seed is statistically more likely to appear in certain places in the resulting keystream.&lt;/p&gt;
&lt;p&gt;In WEP, RC4 is used in the following way:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;User knows a password (fixed)&lt;/li&gt;
&lt;li&gt;To seed RC4 and encrypt packets, users use &lt;code&gt;IV || password&lt;/code&gt; as a seed, where &lt;code&gt;IV&lt;/code&gt; is an Initialization Vector made of 3 random bytes. Each packet has its own &lt;code&gt;IV&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The attack is statistical and targets one byte of the password at a time: if an &lt;code&gt;IV&lt;/code&gt; (3-byte value) is in the form &lt;code&gt;(L,255,X)&lt;/code&gt; (where &lt;code&gt;X&lt;/code&gt; is any value) then it&amp;rsquo;s a vulnerable IV: the resulting keystream will leak data about the Lth byte of the RC4 seed (=&lt;code&gt;IV || password&lt;/code&gt;). By looking for IVs matching &lt;code&gt;(3,255,X)&lt;/code&gt; one can statistically guess the first byte of the password, IVs matching &lt;code&gt;(4,255,X)&lt;/code&gt; leak the second byte, &lt;code&gt;(5,255,X)&lt;/code&gt; the third, and so on.&lt;/p&gt;
&lt;p&gt;This is the first time I&amp;rsquo;ve understood why WEP is insecure on a deep level.&lt;/p&gt;
&lt;h1 id=&#34;confusion-vs-diffusion&#34;&gt;Confusion vs. diffusion&lt;/h1&gt;
&lt;p&gt;First time I&amp;rsquo;ve heard about these two concepts in the context of stream and block ciphers. The book states:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Confusion hides the relation between plaintext and ciphertext. Diffusion distributes the effect of each plaintext byte over many ciphertext bytes.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I thought that was a neat way to summarize the essential difference between stream ciphers (which use confusion) and block ciphers (which use diffusion.)&lt;/p&gt;
&lt;h1 id=&#34;a-reminder-on-ecb-and-cbc&#34;&gt;A reminder on ECB and CBC&lt;/h1&gt;
&lt;p&gt;Because block ciphers operate on blocks of data, it&amp;rsquo;s natural to chunk the plaintext into blocks, and encrypt each block independently. This mode of operation is called &amp;ldquo;Electronic Code Book&amp;rdquo; (ECB) and leads to catastrophic problems, because the same block of plaintext encrypted multiple times yields the same block of ciphertext! Summarized with this famous picture:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/ecb-penguin.png&#34; alt=&#34;ECB penguin&#34;&gt;&lt;/p&gt;
&lt;p&gt;The fix for this is a new block encryption &amp;ldquo;mode&amp;rdquo;: Cipher-Block Chaining (CBC), where blocks of data to encrypt are XOR&amp;rsquo;d with the previous block ciphertext before being encrypted (for the first block to encrypt, it&amp;rsquo;s XOR&amp;rsquo;d with a public Initialization Vector because there is no previous ciphertext to use).&lt;/p&gt;
&lt;p&gt;I found the explanation in the book crystal clear, and a nice reminder (or primer, if you have not seen this before!) on why block cipher modes are so important to get right.&lt;/p&gt;
&lt;h1 id=&#34;padding-oracle-attack&#34;&gt;Padding oracle attack&lt;/h1&gt;
&lt;p&gt;Another term widely used in the security industry, and explained well in the book. What it boils down to: an attacker shouldn&amp;rsquo;t be able to differentiate between a decryption operation which fails because the padding is incorrect vs. a complete failure to decrypt.&lt;/p&gt;
&lt;p&gt;This &amp;ldquo;one bit&amp;rdquo; of information is enough to crack a ciphertext byte by byte:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Take a ciphertext you know is valid.&lt;/li&gt;
&lt;li&gt;Work block by block, starting at the end.&lt;/li&gt;
&lt;li&gt;For each byte in a block, brute force one byte at a time: try all 256 values until there is no padding error.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is a good reminder that if you&amp;rsquo;re working with sensitive workloads, granular error messages or error codes can lead to catastrophic consequences by leaking information to attackers.&lt;/p&gt;
&lt;h1 id=&#34;beast-explained&#34;&gt;BEAST explained&lt;/h1&gt;
&lt;p&gt;Another real-world exploit explained and implemented end-to-end: &lt;a href=&#34;https://nvd.nist.gov/vuln/detail/CVE-2011-3389&#34;&gt;BEAST&lt;/a&gt; (stands for &amp;ldquo;Browser Exploit Against SSL/TLS&amp;rdquo;). I highly recommend reading this chapter (section 5.5) and the associated code. I wouldn&amp;rsquo;t do it justice by trying to explain it here, but it&amp;rsquo;s impressive that the authors managed to fit a full explanation and implementation for this exploit into a book chapter. I&amp;rsquo;ll leave you with a teaser: below is the diagram they work towards:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/beast-diagram.png&#34; alt=&#34;BEAST diagram&#34;&gt;&lt;/p&gt;
&lt;p&gt;True beast of a diagram.&lt;/p&gt;
&lt;h1 id=&#34;birthday-paradox-and-rainbow-tables&#34;&gt;Birthday paradox and rainbow tables&lt;/h1&gt;
&lt;p&gt;Chapter 6 of the book covers a topic that&amp;rsquo;s well-covered everywhere: hash functions. Two concepts that are worth drilling home:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Birthday paradox&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;It takes a lot fewer people than you&amp;rsquo;d think to arrive at a group of people with &lt;em&gt;at least one pair&lt;/em&gt; of people sharing a birthday. The parallel with hash functions is clear: it takes a lot fewer tries than you&amp;rsquo;d think for &lt;em&gt;any one pair&lt;/em&gt; of inputs to share the same digest.&lt;/p&gt;
&lt;p&gt;For a hash function producing digests which are of length N bits, there are `2^N` possible digest values, but it only takes `2^{N/2}` attempts to reach a 50% chance of generating a hash collision. More about the birthday paradox &lt;a href=&#34;https://en.wikipedia.org/wiki/Birthday_problem&#34;&gt;here&lt;/a&gt;, and more about collision resistance &lt;a href=&#34;https://en.wikipedia.org/wiki/Collision_resistance&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Rainbow tables&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I was under the impression that rainbow tables were simple key-value stores with digests as keys and passwords as values to allow attackers to reverse hash functions (and go from a stolen password digest to the actual password).&lt;/p&gt;
&lt;p&gt;This isn&amp;rsquo;t true: rainbow tables are an &lt;strong&gt;optimization&lt;/strong&gt; on top of this naive &amp;ldquo;simple lookup&amp;rdquo; approach. Rainbow tables rely on hash &lt;strong&gt;chains&lt;/strong&gt; which alternate between applying a hash function &lt;em&gt;and a reduce function&lt;/em&gt;, which goes from a digest value back to a candidate password deterministically. The optimization lies in the fact that a rainbow table only needs to store the start and the end of each hash chain, instead of storing all the intermediate digest values. How would lookups work for digests which are not stored, you say? That&amp;rsquo;s where the trick is. The lookup function isn&amp;rsquo;t a single DB lookup — it involves multiple lookups and computation:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;lookup a target &lt;code&gt;digest&lt;/code&gt; value&lt;/li&gt;
&lt;li&gt;if not found, lookup &lt;code&gt;digest2=hash(reduce(digest))&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;if not found, lookup &lt;code&gt;digest3=hash(reduce(digest2))&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&amp;hellip;and so on until you&amp;rsquo;ve done this N times, where N is the length of the hash chain. If nothing is returned by that point, then the lookup has failed.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is a clever way to trade-off space for time complexity. The book also explains why reduce functions must be indexed so that they&amp;rsquo;re different for each successive reduce operation: it avoids hash chains merging together. The result is the following diagram, which is a great, concise visual to remember why rainbow tables are called &amp;ldquo;rainbow tables&amp;rdquo;:&lt;/p&gt;
&lt;img src=&#34;https://arnaudbrousseau.com/img/rainbow-tables.png&#34; alt=&#34;Why Rainbow tables are called rainbow tables&#34; style=&#34;max-width: 560px&#34; /&gt;
&lt;p&gt;No way to un-see this once it clicks!&lt;/p&gt;
&lt;h1 id=&#34;just-use-hmac&#34;&gt;Just use HMAC&lt;/h1&gt;
&lt;p&gt;The book explains in detail how different types of Message Authentication Codes (MACs) fail:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Secret-prefix MACs (where &lt;code&gt;MAC = hash(secret || message)&lt;/code&gt;) are vulnerable to &lt;a href=&#34;https://github.com/krkhan/crypto-impl-exploit/tree/main/ch07/length_ext&#34;&gt;length-extension attacks&lt;/a&gt;. Length-extension attacks work on hash functions which use the &lt;a href=&#34;https://en.wikipedia.org/wiki/Merkle%E2%80%93Damg%C3%A5rd_construction&#34;&gt;Merkle–Damgård&lt;/a&gt; construction. In short, an attacker can construct &lt;code&gt;H(A||B)&lt;/code&gt; from &lt;code&gt;H(A)&lt;/code&gt; alone, without knowing &lt;code&gt;A&lt;/code&gt;!&lt;/li&gt;
&lt;li&gt;Secret-suffix MACs (where &lt;code&gt;MAC = hash(message || secret&lt;/code&gt;) aren&amp;rsquo;t vulnerable to length-extension attacks but vulnerable to collision attacks.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The solution: when you need a MAC, use &lt;a href=&#34;https://en.wikipedia.org/wiki/HMAC&#34;&gt;HMAC&lt;/a&gt;. It fixes both problems.&lt;/p&gt;
&lt;h1 id=&#34;common-factors-attack-on-rsa&#34;&gt;Common factors attack on RSA&lt;/h1&gt;
&lt;p&gt;Something I learned while reading this book: there was an at-scale compromise of many RSA keys because they were not generated with good-enough entropy. This reminds me of &lt;a href=&#34;https://milksad.info/&#34;&gt;Milksad&lt;/a&gt;, a vulnerability caused by weak entropy during crypto key generation.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/weak-rsa-at-scale.png&#34; alt=&#34;weak RSA keys at scale&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.usenix.org/system/files/conference/usenixsecurity12/sec12-final228.pdf&#34;&gt;The original paper&lt;/a&gt; is worth a read. If you&amp;rsquo;re looking for an implementation of the exploit, head &lt;a href=&#34;https://github.com/krkhan/crypto-impl-exploit/tree/main/ch08/common_factors&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h1 id=&#34;small-exponent-attack-wieners&#34;&gt;Small exponent attack (Wiener&amp;rsquo;s)&lt;/h1&gt;
&lt;p&gt;Mind-blowing attack because it relies on a mathematical theorem: &lt;a href=&#34;https://en.wikipedia.org/wiki/Wiener%27s_attack#Wiener&#39;s_theorem&#34;&gt;Wiener&amp;rsquo;s Theorem&lt;/a&gt;. Exponents which are smaller than a threshold are vulnerable — there&amp;rsquo;s nothing anyone can do about it. That&amp;rsquo;s beautiful and scary at the same time: makes you wonder how much we truly know about the current crypto systems in use today. How many Wiener-style attacks exist but are currently unknown?&lt;/p&gt;
&lt;p&gt;The book implements it fully: see the code for yourself &lt;a href=&#34;https://github.com/krkhan/crypto-impl-exploit/blob/main/ch08/short_priv_exp/exploit_short_priv_exp/exploit_short_priv_exp.go&#34;&gt;here&lt;/a&gt;, it&amp;rsquo;s less than 50 lines.&lt;/p&gt;
&lt;h1 id=&#34;rsa-fixed-points&#34;&gt;RSA fixed points&lt;/h1&gt;
&lt;p&gt;Another lightbulb moment: I didn&amp;rsquo;t know RSA had fixed points. A fixed point is a plaintext which, when encrypted, yields itself. This seems like a serious bug to me! Here&amp;rsquo;s a visual for RSA fixed points:&lt;/p&gt;
&lt;img src=&#34;https://arnaudbrousseau.com/img/rsa-fixed-points.png&#34; alt=&#34;RSA fixed points&#34; style=&#34;max-width: 600px&#34; /&gt;
&lt;p&gt;From the book: &amp;ldquo;every RSA keypair has at least nine of them&amp;rdquo;. I found this surprising! The main defense against fixed points is randomized padding schemes, to make the odds of ending up on a fixed point negligible. But it doesn&amp;rsquo;t eliminate the possibility, it just makes it very small!&lt;/p&gt;
&lt;h1 id=&#34;nonce-reuse-attacks&#34;&gt;Nonce-reuse attacks&lt;/h1&gt;
&lt;p&gt;For readers who have not seen a nonce-reuse attack in action yet I highly recommend diving into the details of the math. It&amp;rsquo;s simple linear algebra. Reusing a nonce leads to full private key compromise, period.&lt;/p&gt;
&lt;p&gt;This might break your mental model: if you think avoiding theft of your private key is enough to keep it safe&amp;hellip;think again: If you&amp;rsquo;re tricked into using your private key to sign 2 different messages with the same nonce, your private key is gone. Whoops. This is what happened recently in &lt;a href=&#34;https://github.com/indutny/elliptic/security/advisories/GHSA-vjh7-7g9h-fjfh&#34;&gt;this elliptic library vulnerability&lt;/a&gt;. Stay tuned, I&amp;rsquo;ll write about that more in the near future.&lt;/p&gt;
&lt;p&gt;The defense against this is deterministic nonces (&lt;a href=&#34;https://datatracker.ietf.org/doc/html/rfc6979&#34;&gt;RFC 6979&lt;/a&gt;), or even better, &lt;a href=&#34;https://paulmillr.com/posts/deterministic-signatures/&#34;&gt;hedged signatures&lt;/a&gt;.&lt;/p&gt;
&lt;h1 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;&lt;em&gt;Hacking Cryptography&lt;/em&gt; sits in that rare category of books that manage to make theory feel alive. It doesn’t just tell you that cryptography can fail; it shows you why, and it shows you how. Summary of what stuck with me deeply:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;True randomness comes from messy physics, and the best TRNGs are those with a clear, testable physical model like MEM-based designs. Without an underlying physical model, you can’t measure or trust your source of randomness.&lt;/li&gt;
&lt;li&gt;Even “true” random sources need mathematical cleanup to produce uniform, high-entropy output! Randomness extractors must be used on top of physical entropy sources.&lt;/li&gt;
&lt;li&gt;CSPRNGs vs. PRNGs: the line between “secure” and “insecure” PRNGs isn’t about randomness itself, but about how the underlying &amp;ldquo;next state&amp;rdquo; and &amp;ldquo;next output&amp;rdquo; functions are secure against inversion.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;DUAL_EC_BG&lt;/code&gt; exploit is a very elegant backdoor, courtesy of our friends at the NSA. You have to know the backdoor to prove that there is a backdoor. We still do not know whether &lt;code&gt;DUAL_EC_BG&lt;/code&gt; is actually backdoor&amp;rsquo;d, to this day.&lt;/li&gt;
&lt;li&gt;Stream ciphers are a practical solution to the limitation of One-Time Pads when the amount of data to encrypt grows larger and larger.&lt;/li&gt;
&lt;li&gt;WEP is insecure because of the underlying statistical bias in RC4. Incredible find and exploit.&lt;/li&gt;
&lt;li&gt;Padding oracle attacks are a good reminder that error messages, if they leak just one bit too much information, can lead to catastrophic consequences.&lt;/li&gt;
&lt;li&gt;Need a MAC? Just use HMAC.&lt;/li&gt;
&lt;li&gt;Pure math can be a sharp weapon: Wiener&amp;rsquo;s attack on small RSA exponents is a masterclass.&lt;/li&gt;
&lt;li&gt;Every RSA keypair has at least nine fixed points.&lt;/li&gt;
&lt;li&gt;Preventing key theft isn’t enough to protect your private key — nonce reuse can reveal it entirely. All that&amp;rsquo;s needed are two public signatures sharing the same nonce.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you already work with crypto, this book will give you new mental models and sharpen your intuition for what can go wrong. If you’re new to the field, it will give you a practical foundation rooted in real attacks rather than abstract concepts.&lt;/p&gt;
&lt;p&gt;I came away from it with a renewed appreciation for simplicity, paranoia, and humility when dealing with cryptography.&lt;/p&gt;
&lt;p&gt;Thanks for reading!&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Mythical Man-Month Nuggets</title>
      <link>https://arnaudbrousseau.com/notes/mythical-man-month-nuggets.html</link>
      <pubDate>Sun, 23 Jun 2024 08:17:55 -0500</pubDate>
      <guid>https://arnaudbrousseau.com/notes/mythical-man-month-nuggets.html</guid>
      <description>&lt;p&gt;I recently read through &lt;a href=&#34;https://www.amazon.com/Mythical-Man-Month-Software-Engineering-Anniversary/dp/0201835959&#34;&gt;The Mythical Man-Month&lt;/a&gt;, a book I&amp;rsquo;ve heard about a lot over the years. It&amp;rsquo;s a classic. Many blog posts reference it. It&amp;rsquo;s as ingrained in Silicon Valley culture as the Great Gatsby is in New York&amp;rsquo;s.&lt;/p&gt;
&lt;p&gt;I went to the source out of curiosity: is this book still relevant, ~50 years later?&lt;/p&gt;
&lt;p&gt;Going in I thought I&amp;rsquo;d read about the process of software estimation, the fallacy of adding people to a project late, and the fact that engineers are not fungible. These are the contexts in which &amp;ldquo;the mythical man-month&amp;rdquo; has been referenced for me.&lt;/p&gt;
&lt;p&gt;What I found instead was a series of essays on a pretty wide variety of topics related to software engineering, most of them still relevant, and some of them illuminating.&lt;/p&gt;
&lt;p&gt;Parts of this book resonated so much that I think they deserve their own space here. What follows are noteworthy quotes which triggered mini &amp;ldquo;aha!&amp;rdquo; moments, because of their pithiness or prescience (this book was published in 1975!).&lt;/p&gt;
&lt;h2 id=&#34;tar-pits&#34;&gt;Tar pits&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;No scene from prehistory is quite so vivid as that of the mortal struggles of great beasts in the tar pits [&amp;hellip;]. The fiercer the struggle, the more entangling the tar [&amp;hellip;]. Large system programming has over the past decade been such a tar pit.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The tar pit image is vivid and is a perfect metaphor for that feeling when working in a giant organization, operating in a legacy codebase, or both. IYKYK.&lt;/p&gt;
&lt;h2 id=&#34;programming-is-thought-stuff&#34;&gt;Programming is thought-stuff&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;The programmer, like the poet, works only slightly removed from pure thought-stuff. He builds his castle in the air, from air, creating by exertion of the imagination&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I&amp;rsquo;ve always thought that programming and writing are &lt;a href=&#34;https://twitter.com/arnaudbrousseau/status/1784303394024304743&#34;&gt;much closer than people think&lt;/a&gt;. Thinking of software as &amp;ldquo;thought-stuff&amp;rdquo; is a nice epiphany: it&amp;rsquo;s indeed like poetry, like authoring an essay, like drawing plans. All &amp;ldquo;thought&amp;rdquo;-stuff.&lt;/p&gt;
&lt;h2 id=&#34;parallelism&#34;&gt;Parallelism&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;The bearing of a child takes nine months, no matter how many women are assigned. Many software tasks have this characteristic because of the sequential nature of debugging&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Powerful analogy to convey the heresy of trying to parallelize a process that&amp;rsquo;s inherently single-threaded. Some programming tasks are, but let&amp;rsquo;s be honest: most aren&amp;rsquo;t and have some degree of parallelism. You just have to look for these tracks and get creative.&lt;/p&gt;
&lt;h2 id=&#34;readiness&#34;&gt;Readiness&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;An omelet, promised in 2 minutes, may appear to be progressing nicely. But when it has not set in two minutes, the customer has 2 choices&amp;ndash;wait or eat it raw.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This is a powerful analogy to say: once a project is late it&amp;rsquo;s extremely hard to get it back on its original timeline. Better take a delay than ship a buggy product. I&amp;rsquo;ve found that defining what &amp;ldquo;ready&amp;rdquo; looks like is crucial at the start of a project; it helps to have that as a reference later on if delays happen.&lt;/p&gt;
&lt;h2 id=&#34;brooks-law&#34;&gt;Brook&amp;rsquo;s law&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Brook&amp;rsquo;s law: adding manpower to a late software project makes it later&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That&amp;rsquo;s the most cited sentence in the book. There&amp;rsquo;s a lot more nuance to it, the author actually goes into details on why things slow down as well as some remedies for late software projects. But it&amp;rsquo;s a good &amp;ldquo;0th degree approximation&amp;rdquo;. A good rule of thumb. As a manager: resist the temptation, don&amp;rsquo;t add people to a late project.&lt;/p&gt;
&lt;h2 id=&#34;10x-engineers&#34;&gt;10x engineers&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Programming managers have long recognized wide productivity variations between good programmers and poor ones. But the actual measured magnitudes have astounded all of us. In one of their studies, Sackman, Erikson, and Grant were measuring performances of a group of experienced programmers. Within just this group the ratios between best and worst performances averaged about 10:1 on productivity measurements.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Aha! So &lt;em&gt;that&lt;/em&gt; is where the mythical &amp;ldquo;10x engineer&amp;rdquo; comes from!&lt;/p&gt;
&lt;h2 id=&#34;on-mighty-small-teams&#34;&gt;On mighty small teams&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;The problem with the small, sharp team concept: it is too slow for really big systems&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;If you&amp;rsquo;ve bought into the idea that startups are always better because things move faster, this may be an awakening. Silicon Valley culture glorifies efforts by a couple of engineers building a prototype in a weekend, or progress made by small teams over a few weeks, as if bigger teams were always the wrong choice because they&amp;rsquo;re less efficient.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s a breath of fresh air to have the other side stated clearly: yes, smaller teams move faster, but small teams are &lt;strong&gt;overall too slow&lt;/strong&gt; for &amp;ldquo;big systems&amp;rdquo;. No amount of productivity gains will get you there: you need a bigger team for a bigger system. This was true 50 years ago, but is it still as true today?&lt;/p&gt;
&lt;h2 id=&#34;surgical-teams&#34;&gt;Surgical teams&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Mills proposes that each segment of a large job be tackled by a team, but that the team be organized like a surgical team rather than a hog-butchering team&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;What Brooks means by a &amp;ldquo;surgical&amp;rdquo; team is a team organized around one person who makes decisions and holds the high-level task in their head. The rest of the team plays &amp;ldquo;support&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Intuitively this makes a lot of sense: this structure minimizes the time it takes to make decisions. I&amp;rsquo;ve often seen issues when there are &amp;ldquo;too many cooks in the kitchen&amp;rdquo;, so the surgical team model makes sense. It loosely maps to the modern day concept of &amp;ldquo;tech lead&amp;rdquo; on any given project, or the concept of &amp;ldquo;architect&amp;rdquo; in large organizations. The failure mode is obvious: if the surgeon is bad, there&amp;rsquo;s no saving the project or team organized around them.&lt;/p&gt;
&lt;h2 id=&#34;conceptual-integrity&#34;&gt;Conceptual integrity&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Conceptual integrity is &lt;em&gt;the&lt;/em&gt; most important consideration in system design. It is better to have a system omit certain anomalous features and improvements, but to reflect one set of design ideas, than to have one that contains many good but independent and uncoordinated ideas&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Amen. The fact that this was written in 1975 blows my mind. &amp;ldquo;Conceptual integrity&amp;rdquo; is definitely a term I&amp;rsquo;ll reference in future discussions. Another related quote from the same essay:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Conceptual integrity in turn dictates that the design must proceed from one mind, or from a very small number of agreeing resonant minds&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This explains why design by committee is often a tragic mistake, and also why &amp;ldquo;team alignment&amp;rdquo; is so amorphous yet weirdly valuable to shoot for. Aligned teams or &amp;ldquo;resonant minds&amp;rdquo; build tighter systems, with better conceptual integrity.&lt;/p&gt;
&lt;h2 id=&#34;second-systems&#34;&gt;Second systems&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;The general tendency is to over-design the second system, using all the ideas and frills that were cautiously sidetracked on the first one.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Known as the &amp;ldquo;Second-System Effect&amp;rdquo;. This is surprisingly still relevant today: when a first system is replaced by a second, it ends up being late, clunky, and expensive. A &amp;ldquo;big pile&amp;rdquo; with no conceptual integrity.&lt;/p&gt;
&lt;h2 id=&#34;tower-of-babel-projects&#34;&gt;Tower of Babel projects&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Schedule disaster, functional misfits, and system bugs all arise because the left hand doesn&amp;rsquo;t know what the right hand is doing. As work proceeds, the several teams slowly change the functions, sizes, and speeds of their own programs and they explicitly or implicitly change their assumptions about the inputs available and the uses to be made of the outputs.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I haven&amp;rsquo;t seen a large organization where this doesn&amp;rsquo;t happen in some flavor. Communication breakdown is by far, still today, the biggest cause of project failures or delays. I&amp;rsquo;m not sure if the communication problems of today are better or worse than in the 70s. Back then they had excuses because communication was costly. Paper documents were hard to produce and distribute. Today none of this is true anymore. There are no excuses.&lt;/p&gt;
&lt;h2 id=&#34;the-essence-of-programming&#34;&gt;The essence of programming&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Beyond craftsmanship lies invention, and it is here that lean, spare, fast programs are born. Almost always these are the result of strategic breakthrough rather than tactical cleverness [&amp;hellip;] strategic breakthrough will come from redoing the representation of the data or tables. This is where the heart of a program lies. [&amp;hellip;] Representation &lt;em&gt;is&lt;/em&gt; the essence of programming.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;No commentary needed here, this insight is as fresh as they come, decades later.&lt;/p&gt;
&lt;h2 id=&#34;throw-one-away&#34;&gt;Throw one away&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;The management question, therefore, is not whether to build a pilot system and throw it away. You &lt;em&gt;will&lt;/em&gt; do that. The only question is whether to plan in advance to build a throwaway, or to promise to deliver the throwaway to customers. [&amp;hellip;] Hence plan to throw one away; you will, anyhow.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This has now been completely integrated into everyday software development. The notion of prototyping is widely accepted. We don&amp;rsquo;t throw a single one away typically, we throw away many! Finally something we&amp;rsquo;ve become better at over the last five decades.&lt;/p&gt;
&lt;h2 id=&#34;design-docs&#34;&gt;Design docs&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;The reluctance to document designs is not due merely to laziness or time pressure. Instead it comes from the designer&amp;rsquo;s reluctance to commit himself to the defense of decisions which he knows to be tentative&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The cliché of lazy programmers who do not want to write documentation has some amount of truth to it, but it fails to account for the social aspect of documentation: once it&amp;rsquo;s written down, it&amp;rsquo;s official. When no documentation is produced, ask yourself why: are programmers lazy? Do they disagree? Or do they not know?&lt;/p&gt;
&lt;h2 id=&#34;programming-and-entropy&#34;&gt;Programming and Entropy&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Program building is an entropy-decreasing process, hence inherently metastable. Program maintenance is an entropy-increasing process, and even its most skillful execution only delays the subsidence of the system into unfixable obsolescence.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;What a great way to frame the concept of tech debt!&lt;/p&gt;
&lt;h2 id=&#34;how-are-projects-delayed-by-months-one-day-at-a-time&#34;&gt;How are projects delayed by months? One day at a time!&lt;/h2&gt;
&lt;p&gt;This quote is long but I couldn&amp;rsquo;t really shorten it by much. It&amp;rsquo;s perfect as-is and shows how little has changed when it comes to software project management:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;When one hears of disastrous schedule slippage in a project, he imagines that a series of major calamities must have befallen it. Usually, however, the disaster is due to termites, not tornadoes; and the schedule has slipped imperceptibly but inexorably. Indeed, major calamities are easier to handle; one responds with major force, radical reorganization, the invention of new approaches. The whole team rises to the occasion.
But the day-by-day slippage is harder to recognize, harder to prevent, harder to make up. Yesterday a key man was sick, and a meeting couldn&amp;rsquo;t be held. Today the machines are all down, because lightning struck the building&amp;rsquo;s power transformer. Tomorrow the disk routines won&amp;rsquo;t start testing, because the first disk is a week late from the factory. Snow, jury duty, family problems, emergency meetings with customers, executive audits&amp;ndash;the list goes on and on. Each one only postpones some activity by a half-day or a day. And the schedule slips, one day at a time.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;It&amp;rsquo;s indeed much harder to empathize with day-by-day slippage than a &amp;ldquo;tornado&amp;rdquo; type delay. The day-by-day slippage is a morale killer and a slog, whereas a good &amp;ldquo;tornado&amp;rdquo; can inject energy and create a productive wake-up call.&lt;/p&gt;
&lt;p&gt;A great manager can turn the latter into the former, when necessary.&lt;/p&gt;
&lt;h2 id=&#34;essential-vs-accidental-complexity&#34;&gt;Essential vs accidental complexity&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;All software construction involves essential tasks, the fashioning of the complex conceptual structures that compose the abstract software entity, and accidental tasks, the representation of these abstract entities in programming languages and the mapping of these onto machine languages within space and speed constraints.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This rings true and reminds me of &lt;a href=&#34;https://www.youtube.com/watch?v=SxdOUGdseq4&#34;&gt;&amp;ldquo;Simple made Easy&amp;rdquo;&lt;/a&gt;, a talk by Rich Hickey (creator of &lt;a href=&#34;https://clojure.org/&#34;&gt;Clojure&lt;/a&gt;, and one of my favorite tech speakers). The main point of this talk is that &amp;ldquo;simple&amp;rdquo; is different from &amp;ldquo;easy&amp;rdquo;. And it relates to the notion of essential vs accidental complexity quoted above: &amp;ldquo;simple&amp;rdquo; can be defined as &amp;ldquo;low essential complexity&amp;rdquo;, and &amp;ldquo;easy&amp;rdquo; as &amp;ldquo;low accidental complexity&amp;rdquo;. These two sets of concepts clicked satisfyingly in place together in my brain.&lt;/p&gt;
&lt;h2 id=&#34;hammock-programming&#34;&gt;Hammock programming&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;The essence of a software entity is a construct of interlocking concepts: data sets, relationships among data items, algorithms, and invocation of functions. This essence is abstract, in that the conceptual construct is the same under many different representations. It is nonetheless highly precise and richly detailed. I believe the hard part of building software to be the specification, design, and testing of this conceptual construct, not the labor of representing and testing the fidelity of the representation. We still make syntax errors, to be sure; but they are fuzz compared to the conceptual errors in most systems.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Have you ever experienced solving a programming problem while in the shower? I bet. The quote above explains this neatly: the main difficulty in software, the &amp;ldquo;essence&amp;rdquo; of it, is the initial construction of the ideas and relationships. Not the actual implementation.&lt;/p&gt;
&lt;p&gt;Rich Hickey (him again!) gave an excellent talk on the subject of working with abstract ideas: &lt;a href=&#34;https://www.youtube.com/watch?v=f84n5oFoZBc&amp;amp;t=1s&#34;&gt;Hammock Driven Development&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;complexity-the-root-of-all-evil&#34;&gt;Complexity: the root of all evil&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Many of the classical problems of developing software products derive from this essential complexity and its nonlinear increase with size. From the complexity comes the difficulty of communication among team members, which leads to product flaws, cost overruns, schedule delays. From the complexity comes the difficulty of enumerating, much less understanding, all the possible states of the program, and from that comes the unreliability. From the complexity of the functions comes the difficulty of invoking those functions, which makes programs hard to use. From complexity of structure comes the difficulty of extending programs to new functions without creating side effects. From complexity of structure comes the unvisualized states that constitute security trapdoors.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Excellent explanation of why simplicity (talking about &amp;ldquo;essential&amp;rdquo; simplicity here, although accidental complexity is also bad) is the number one security feature. Do one thing, do it well. That&amp;rsquo;s the root of the Unix philosophy.&lt;/p&gt;
&lt;p&gt;This quote continues and concludes:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Not only technical problems but management problems as well come from the complexity. This complexity makes overview hard, thus impeding conceptual integrity. It makes it hard to find and control all the loose ends. It creates the tremendous learning and understanding burden that makes personnel turnover a disaster.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;A team working on a complex codebase or product is harder to motivate than a team working on a greenfield or mostly-greenfield one. Complexity kills morale.&lt;/p&gt;
&lt;h2 id=&#34;prospects-of-ai&#34;&gt;Prospects of AI&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Many people expect advances in artificial intelligence to provide the revolutionary breakthrough that will give order-of-magnitude gains in software productivity and quality. I do not. [&amp;hellip;] The hard thing about building software is deciding what to say, not saying it. No facilitation of expression can give more than marginal gains.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Bold claim to make in 1975! And interesting to read that AI was already hyped up to be a &amp;ldquo;revolutionary breakthrough&amp;rdquo; back then. We&amp;rsquo;re about to find out if this holds in the face of ChatGPT and friends.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Signatures and ZK proofs: much closer than you think</title>
      <link>https://arnaudbrousseau.com/notes/signatures-and-zk-proofs.html</link>
      <pubDate>Mon, 30 Oct 2023 09:17:01 -0500</pubDate>
      <guid>https://arnaudbrousseau.com/notes/signatures-and-zk-proofs.html</guid>
      <description>&lt;script&gt; MathJax = { loader: { load: [&#39;input/asciimath&#39;, &#39;output/chtml&#39;] } }; &lt;/script&gt;
&lt;script type=&#34;text/javascript&#34; src=&#34;https://arnaudbrousseau.com/js/mathjax/tex-chtml.js&#34; id=&#34;MathJax-script&#34; async&gt;&lt;/script&gt;
&lt;h1 id=&#34;credits-where-credits-are-due&#34;&gt;Credits where credits are due&lt;/h1&gt;
&lt;p&gt;&lt;a href=&#34;https://www.manning.com/books/real-world-cryptography&#34;&gt;Real-World Cryptography&lt;/a&gt; is an excellent book I&amp;rsquo;d recommend to any engineer, but especially to engineers working with modern cryptographic primitives or libraries. After reading through it, what&amp;rsquo;s impressed me most is the explanation of digital signatures in section 7.2. It&amp;rsquo;s introduced in a way I&amp;rsquo;ve never seen before. What follows in my own take on it, hope you like it!&lt;/p&gt;
&lt;h1 id=&#34;signatures-the-usual-explanation&#34;&gt;Signatures: the usual explanation&lt;/h1&gt;
&lt;p&gt;Signatures in cryptography are typically introduced by thinking about the &amp;ldquo;sign&amp;rdquo; and &amp;ldquo;verify&amp;rdquo; primitives in the abstract (diagram from my copy of the book, p. 130):&lt;/p&gt;
&lt;center&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/signatures-sign-and-verify-functionality.png&#34; alt=&#34;Sign and Verify functionality&#34; width=&#34;500&#34; /&gt;&lt;/center&gt;
&lt;ul&gt;
&lt;li&gt;&amp;ldquo;sign&amp;rdquo; takes a message and a private key; produces a signature&lt;/li&gt;
&lt;li&gt;&amp;ldquo;verify&amp;rdquo; takes a message, a public key, and a signature; produces a binary &amp;ldquo;true&amp;rdquo; or &amp;ldquo;false&amp;rdquo; result which indicates whether a signature is valid.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now time for some formulas used to compute or verify signatures.&lt;/p&gt;
&lt;p&gt;To sign (`x` is the private key, `M` the message):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Select a random `k`, then compute `r = g^k`&lt;/li&gt;
&lt;li&gt;Compute  `e = H (r || M)`&lt;/li&gt;
&lt;li&gt;Compute  `s = k - xe`&lt;/li&gt;
&lt;li&gt;Return `(s, e)` as the signature&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And to verify (`p` is the public key):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Compute `r = g^sp^e`&lt;/li&gt;
&lt;li&gt;Compute `e_v = H(r || M)`&lt;/li&gt;
&lt;li&gt;If `e_v stackrel{?}{=} e`, the signature is valid&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;hellip;and off you go! The above explanation is &amp;ldquo;fine&amp;rdquo; and that&amp;rsquo;s what we&amp;rsquo;re used to. But the formulas feel arbitrary, complex, hard to remember, and mysterious.&lt;/p&gt;
&lt;h1 id=&#34;signatures-can-be-seen-as-zk-proofs&#34;&gt;Signatures can be seen as ZK proofs&lt;/h1&gt;
&lt;p&gt;When a signature is verified, the verifier obtains proof that the signer knows a number (their private key), &lt;strong&gt;without knowing what this number is&lt;/strong&gt;. Hence signatures can be seen as zero-knowledge proofs. I&amp;rsquo;ve always thought that this was pretty neat and cool, but ultimately not something very central to the notion of digital signatures. How wrong I was!&lt;/p&gt;
&lt;h1 id=&#34;zk-proofs-are-the-origin-of-digital-signatures&#34;&gt;ZK proofs are the origin of digital signatures&lt;/h1&gt;
&lt;p&gt;Digital signatures can be introduced as a direct evolution of zero-knowledge protocols, and more specifically the &lt;a href=&#34;https://www.zkdocs.com/docs/zkdocs/zero-knowledge-protocols/schnorr/&#34;&gt;Schnorr identification protocol&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The solution to demystifying digital signature formulas is to show where they come from! Let&amp;rsquo;s start from scratch and consider a simple scenario: Alice wants to prove to Bob she knows a number `s` (secret) &lt;em&gt;without revealing it&lt;/em&gt;.&lt;/p&gt;
&lt;h2 id=&#34;a-toy-zk-proof-based-on-division&#34;&gt;A toy ZK proof based on division&lt;/h2&gt;
&lt;p&gt;Because Alice doesn&amp;rsquo;t want to reveal her secret we can&amp;rsquo;t send `s` to Bob directly. Alice needs to send him something (a &amp;ldquo;proof&amp;rdquo;) to convince him that she knows `s`. In practice this means we need to define `s` as a number satisfying some kind of constraints. The constraints are public, `s` stays private, and the proof is a way to prove that Alice knows a number which satisfies the constraints.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s make this concrete and simple: we can define `s` as &amp;ldquo;the number such that `10*x=P`&amp;rdquo; where `P` is a public number. &lt;strong&gt;For a moment, let&amp;rsquo;s suspend disbelief and pretend that division is a hard problem&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;How do we prove to Bob knowledge of `s`? Two techniques are at the core of zero-knowledge proofs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The first technique is called &lt;strong&gt;hiding&lt;/strong&gt;: because we assume division is a hard problem, if `x` is a number, `10*x` is called the &lt;strong&gt;hidden&lt;/strong&gt; version of `x`.&lt;/li&gt;
&lt;li&gt;The second technique is called &lt;strong&gt;blinding&lt;/strong&gt;: given some number `x`, I can pick a random value `k`, and `x+k` is called the &lt;strong&gt;blinded&lt;/strong&gt; version of `x`: without knowledge of `x` or `k`, `x+k` is just a random-looking value.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now we can combine these two techniques to create a proof:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Alice &lt;strong&gt;blinds&lt;/strong&gt; her secret value `s`: she picks a random `k` and computes `s_{bl\i\nded} = k + s`&lt;/li&gt;
&lt;li&gt;Alice &lt;strong&gt;hides&lt;/strong&gt; the random `k`: she computes `k_{hidden} = 10*k`&lt;/li&gt;
&lt;li&gt;The proof is `(s_{bl\i\nded}, k_{hidden})`&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Bob can verify this checking `k_{hidden} + P \stackrel{?}{=} 10 * s_{bl\i\nded}`. This works because:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;`k_{hidden} + P`&lt;/li&gt;
&lt;li&gt;`= 10*k + P` (by definition of `k_{hidden}`)&lt;/li&gt;
&lt;li&gt;`= 10*k + 10*s` (by definition of `P`)&lt;/li&gt;
&lt;li&gt;`= 10 * (k + s)` (because multiplication is distributive)&lt;/li&gt;
&lt;li&gt;`= 10 * s_{bl\i\nded}` (by definition of `s_{bl\i\nded}`)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Pause for a second.&lt;/p&gt;
&lt;p&gt;This is it! Aside from a few tweaks I&amp;rsquo;ll explain below we have all the ideas needed to build modern digital signatures. I find this beautiful, simple, and memorable: &lt;strong&gt;one can prove knowledge of a secret by first blinding it with a random value, and sending the blinded secret along with the (hidden) random value&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&#34;tweak-1-prevent-random-cheating&#34;&gt;Tweak #1: prevent random cheating&lt;/h2&gt;
&lt;p&gt;In our toy protocol we trust Alice to pick a truly random `k`, but what if she doesn&amp;rsquo;t?&lt;/p&gt;
&lt;p&gt;One immediate idea to solve this is to involve Bob and have him provide his own random value (&amp;ldquo;challenge&amp;rdquo;) to prevent Alice from cheating. Our protocol becomes an &lt;strong&gt;interactive&lt;/strong&gt; protocol:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Alice picks a random `k` and &lt;strong&gt;hides&lt;/strong&gt; it: `k_{hidden} = 10*k`&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bob sends a challenge `c` to Alice&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Alice &lt;strong&gt;blinds&lt;/strong&gt; her secret with both `k` and `c`: `s_{bl\i\nded} = k + c*s`&lt;/li&gt;
&lt;li&gt;The proof is the same: `(s_{bl\i\nded}, k_{hidden})`&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To verify, Bob checks `k_{hidden} + c*P stackrel{?}{=} 10 * s_{bl\i\nded}`. Now we&amp;rsquo;ve solved the problem of bad randomness, but we have introduced another: both Alice and Bob need to be online because our protocol is interactive.&lt;/p&gt;
&lt;h2 id=&#34;tweak-2-remove-interactivity&#34;&gt;Tweak #2: remove interactivity&lt;/h2&gt;
&lt;p&gt;To remove interactivity from our protocol we can use what Amos Fiat and Adi Shamir &lt;a href=&#34;https://link.springer.com/chapter/10.1007/3-540-47721-7_12&#34;&gt;discovered in 1986&lt;/a&gt;: the Fiat-Shamir transformation (also known as &lt;a href=&#34;https://en.wikipedia.org/wiki/Fiat%E2%80%93Shamir_heuristic&#34;&gt;Fiat-Shamir heuristic&lt;/a&gt;, but I find &amp;ldquo;transformation&amp;rdquo; clearer).&lt;/p&gt;
&lt;p&gt;The idea is simple: because the output of a hash function is both deterministic and unpredictable, we can use this to our advantage: instead of obtaining a random value from Bob, Alice can compute `H(k_{hidden})` and use this as her &amp;ldquo;challenge&amp;rdquo;. No need to wait for a message from Bob! And Bob can be convinced that the challenge is random because of the nature of hash functions. Our protocol becomes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Alice picks a random `k` and &lt;strong&gt;hides&lt;/strong&gt; it: `k_{hidden} = 10*k`&lt;/li&gt;
&lt;li&gt;Alice computes a challenge with Fiat-Shamir: `c = H(k_{hidden})`&lt;/li&gt;
&lt;li&gt;Alice &lt;strong&gt;blinds&lt;/strong&gt; her secret with both `k` and `c`: `s_{bl\i\nded} = k + c*s`&lt;/li&gt;
&lt;li&gt;The proof is the same: `(s_{bl\i\nded}, k_{hidden})`&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To verify Bob checks `k_{hidden} + c*P stackrel{?}{=} 10 * s_{bl\i\nded}` and &lt;strong&gt;has to compute&lt;/strong&gt; `c = H(k_{hidden})` himself. This ensures Alice can&amp;rsquo;t cheat in the hash computation.&lt;/p&gt;
&lt;h2 id=&#34;tweak-3-insert-any-message-you-like&#34;&gt;Tweak #3: insert any message you like!&lt;/h2&gt;
&lt;p&gt;Schnorr realized that anything could be included in the hash input used to generate the challenge. Indeed if `c = H(k_{hidden})` is an unpredictable challenge, so is `c = H(k_{hidden} || &amp;ldquo;hello&amp;rdquo;)` (where `||` represents concatenation).&lt;/p&gt;
&lt;p&gt;As a result Alice can include any message she likes! &lt;em&gt;This is how signatures emerge from proofs of knowledge&lt;/em&gt;: a proof of knowledge of `s` with a chosen message `M` becomes &amp;ldquo;a signature of `M` with `s`&amp;rdquo;. Here&amp;rsquo;s our protocol with this tweak:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Alice picks a random `k` and &lt;strong&gt;hides&lt;/strong&gt; it: `k_{hidden} = 10*k`&lt;/li&gt;
&lt;li&gt;Alice computes a challenge with Fiat-Shamir and &lt;strong&gt;inserts a message of her choice&lt;/strong&gt;: `c = H(k_{hidden} || M)`&lt;/li&gt;
&lt;li&gt;Alice &lt;strong&gt;blinds&lt;/strong&gt; her secret with both `k` and `c`: `s_{bl\i\nded} = k + c*s`&lt;/li&gt;
&lt;li&gt;The proof is the same: `(s_{bl\i\nded}, k_{hidden})`&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Then Bob computes `c = H(k_{hidden} || M)` and checks `k_{hidden} + c*P stackrel{?}{=} 10 * s_{bl\i\nded}`.
We now have a real Schnorr signature scheme! The final tweak is an obvious one: let&amp;rsquo;s pick a truly hard problem instead of division.&lt;/p&gt;
&lt;h2 id=&#34;tweak-4-pick-a-harder-problem&#34;&gt;Tweak #4: pick a harder problem&lt;/h2&gt;
&lt;p&gt;Time to un-suspend disbelief: our toy protocol above isn&amp;rsquo;t secure because it&amp;rsquo;s not hard to invert multiplication by 10. Anyone can retrieve `s` given `P` with a division operation: `s = P/10`.&lt;/p&gt;
&lt;p&gt;Digital signatures use exponentiation modulo a large prime: `x -&amp;gt; g^x mod N`. The inverse is called the &lt;strong&gt;discrete logarithm&lt;/strong&gt;: `x -&amp;gt; log_{g}(x) mod N`, and is &lt;a href=&#34;https://en.wikipedia.org/wiki/Discrete_logarithm&#34;&gt;assumed to be hard&lt;/a&gt; (you read this right: we still don&amp;rsquo;t know for sure!).&lt;/p&gt;
&lt;p&gt;Alice now proves to Bob that she knows `s` when `s` is defined as &amp;ldquo;the number such that `g^s` = `P`&amp;rdquo;, where `P` is public (Alice&amp;rsquo;s &amp;ldquo;public key&amp;rdquo;). In other words: a proof of knowledge of discrete logarithm rather than a proof of knowledge of division previously.&lt;/p&gt;
&lt;p&gt;Surprisingly this tweak doesn&amp;rsquo;t change how signatures are produced much. It only affects how we &amp;ldquo;hide&amp;rdquo; our random `k` in the first step:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Alice picks a random `k` and &lt;strong&gt;hides&lt;/strong&gt; it: `k_{hidden} = g^k`&lt;/li&gt;
&lt;li&gt;Alice computes a challenge with Fiat-Shamir and &lt;strong&gt;inserts a message of her choice&lt;/strong&gt;: `c = H(k_{hidden} || M)`&lt;/li&gt;
&lt;li&gt;Alice &lt;strong&gt;blinds&lt;/strong&gt; her secret with both `k` and `c`: `s_{bl\i\nded} = k + c*s`&lt;/li&gt;
&lt;li&gt;The proof is: `(s_{bl\i\nded}, k_{hidden})`&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Verification changes because multiplication is replaced by exponentiation (notations are harder to read and reason about, which is why I&amp;rsquo;ve stuck to simple multiplication/division until now):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Bob computes `c = H(k_{hidden} || M)`&lt;/li&gt;
&lt;li&gt;Bob checks `k_{hidden}*P^c stackrel{?}{=} g^{s_{bl\i\nded}}`&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now we&amp;rsquo;ve arrived at the real Schnorr signature formula! Typically `k_{hidden}` is called `r`, the challenge `c` is called `e`, and `s_{bl\i\nded}` is simply `s`. &lt;a href=&#34;https://en.wikipedia.org/wiki/Schnorr_signature#Signing&#34;&gt;Check this out on wikipedia&lt;/a&gt;.&lt;/p&gt;
&lt;h1 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;We&amp;rsquo;ve seen the usual explanation for digital signatures and why it sucks: the formulas feel arbitrary and hard to remember. Inspired by section 7.2 of &lt;a href=&#34;https://www.manning.com/books/real-world-cryptography&#34;&gt;Real-World Cryptography&lt;/a&gt; I&amp;rsquo;ve started from a very simple toy zero-knowledge protocol and applied successive tweaks to arrive at real-world Schnorr signatures:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The toy protocol relies on two general tricks: &lt;strong&gt;hiding&lt;/strong&gt; and &lt;strong&gt;blinding&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;We solve for dishonest random numbers by introducing an interactive challenge.&lt;/li&gt;
&lt;li&gt;We remove the interactivity by leveraging the Fiat-Shamir transformation.&lt;/li&gt;
&lt;li&gt;We include messages in non-interactive challenges: &lt;strong&gt;this is the birth of signatures&lt;/strong&gt;!&lt;/li&gt;
&lt;li&gt;Finally we switch from trivial to hard problem (division to discrete logarithm)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With that I hope the formula behind Schnorr signatures feels elegant, memorable, and less arbitrary!&lt;/p&gt;
&lt;hr/&gt;
&lt;small&gt;
P.S: It should also become obvious why &lt;a href=&#34;https://arnaudbrousseau.com/notes/verifying-without-hashing.html&#34; target=&#34;_blank&#34;&gt;verifying a signature without hashing the message is a cardinal sin in cryptography&lt;/a&gt;. Without this step Bob gives up his involvement in the protocol, Alice can cheat by using non-random nonces, and the security of the scheme falls apart: Alice can prove knowledge of her secret key (produce signatures) without actual ownership of it!
&lt;/small&gt;
&lt;hr/&gt;</description>
    </item>
    <item>
      <title>Deadly Sin in Cryptography: Verifying without Hashing</title>
      <link>https://arnaudbrousseau.com/notes/verifying-without-hashing.html</link>
      <pubDate>Tue, 27 Jun 2023 00:10:56 -0500</pubDate>
      <guid>https://arnaudbrousseau.com/notes/verifying-without-hashing.html</guid>
      <description>&lt;p&gt;This is a tale in three parts. First I&amp;rsquo;ll make a convincing claim that I am
Satoshi by providing a never-seen-before, valid signature for one of their
public keys. Then I&amp;rsquo;ll explain the claim&amp;rsquo;s flaws through questions and answers,
and conclude with the moral of the story!&lt;/p&gt;
&lt;h1 id=&#34;why-i-am-satoshi&#34;&gt;Why I am Satoshi&lt;/h1&gt;
&lt;p&gt;Go to any block explorer and look at the first transaction ever made on the Bitcoin network:
&lt;a href=&#34;https://blockchair.com/bitcoin/transaction/0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098&#34;&gt;0e3e&amp;hellip;2098&lt;/a&gt;.
It sent 50BTC to the following address: &lt;code&gt;12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The public key associated with this address is &lt;code&gt;0296b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You can use &lt;a href=&#34;https://iancoleman.io/bitcoin-key-compression/&#34;&gt;this tool&lt;/a&gt; to convince yourself that it&amp;rsquo;s true:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/satoshi-address-public-key.png&#34; alt=&#34;Satoshi address and public key&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;i-can-produce-a-valid-signatures&#34;&gt;I can produce a valid signatures&lt;/h2&gt;
&lt;p&gt;Here is a new and never-seen-before signature, valid for Satoshi&amp;rsquo;s public key:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;R: &lt;code&gt;4bb1b2164d4c82b87e4ba0bf546f0557eacc9b7e3b9c91e0318d21efc8018031&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;S: &lt;code&gt;8912be5021535357e820281174b44d8d0692fd699f052fcc05aec1577b7f819e&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Hash: &lt;code&gt;b6e53001048653817bea00f48000e2c90e547796300853b667746cac08e43420&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Once again: &lt;em&gt;I claim that the above is a valid signature for Satoshi&amp;rsquo;s public
key&lt;/em&gt;, &lt;code&gt;0296b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52&lt;/code&gt;&lt;/p&gt;
&lt;h3 id=&#34;how-can-you-verify-this-2-ways&#34;&gt;How can you verify this? (2 ways!)&lt;/h3&gt;
&lt;p&gt;Any cryptography library will do. Taking two popular libraries as examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/paulmillr/noble-curves&#34;&gt;&lt;code&gt;@noble/curves&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/tlsfuzzer/python-ecdsa/&#34;&gt;&lt;code&gt;python-ecdsa&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Verifying with &lt;code&gt;@noble/curves&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s the source for &lt;code&gt;verify.js&lt;/code&gt;, a Node script importing &lt;code&gt;@noble/curves&lt;/code&gt; only:&lt;/p&gt;
&lt;pre class=&#34;brush:javascript&#34;&gt;
import { secp256k1 } from &#39;@noble/curves/secp256k1&#39;;

const signature = Buffer.from(process.argv[2], &#39;hex&#39;);
const message = Buffer.from(process.argv[3], &#39;hex&#39;);
const publicKey = Buffer.from(process.argv[4], &#39;hex&#39;);

console.log(
    &#34;is valid?&#34;,
    secp256k1.verify(
        signature,
        message,
        publicKey
    )
);
&lt;/pre&gt;
&lt;p&gt;And here&amp;rsquo;s how you&amp;rsquo;d run it to verify the Satohi signature above:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
$ node verify.js 4bb1b2164d4c82b87e4ba0bf546f0557eacc9b7e3b9c91e0318d21efc80180318912be5021535357e820281174b44d8d0692fd699f052fcc05aec1577b7f819e b6e53001048653817bea00f48000e2c90e547796300853b667746cac08e43420 0296b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52
is valid? true
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Verifying with &lt;code&gt;python-ecdsa&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The Python version isn&amp;rsquo;t much longer. Below is &lt;code&gt;verify.py&lt;/code&gt;, a Python script using &lt;code&gt;python-ecdsa&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&#34;brush:python&#34;&gt;
import sys
from ecdsa import curves
from ecdsa import VerifyingKey

if __name__ == &#34;__main__&#34;:
    signature = sys.argv[1]
    digest = sys.argv[2]
    public_key = sys.argv[3]
    
    k = VerifyingKey.from_string(
        bytes.fromhex(public_key),
        curve=curves.SECP256k1
    )
    print(
        &#34;is valid?&#34;,
        k.verify_digest(
            bytes.fromhex(signature),
            bytes.fromhex(digest)
        )
    )
&lt;/pre&gt;
&lt;p&gt;Running this python script with the same Satoshi signature:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
$ pip install ecdsa
$ python verify.py 4bb1b2164d4c82b87e4ba0bf546f0557eacc9b7e3b9c91e0318d21efc80180318912be5021535357e820281174b44d8d0692fd699f052fcc05aec1577b7f819e b6e53001048653817bea00f48000e2c90e547796300853b667746cac08e43420 0296b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52
public key 0296b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52
is valid? True
&lt;/pre&gt;
&lt;p&gt;Are you convinced? Nice. Now onto part two, where we dig into what happened here.&lt;/p&gt;
&lt;h1 id=&#34;why-im-not-satoshi&#34;&gt;Why I&amp;rsquo;m not Satoshi&lt;/h1&gt;
&lt;p&gt;More specifically: why is the claim above not sufficient? After all I&amp;rsquo;m able to
demonstrate that I was able to present a new signature for Satoshi&amp;rsquo;s public
key, and show that it&amp;rsquo;s valid!&lt;/p&gt;
&lt;p&gt;So where&amp;rsquo;s the catch? Let the Socratic dialog begin!&lt;/p&gt;
&lt;h2 id=&#34;this-isnt-the-right-public-key-to-verify-against&#34;&gt;&amp;ldquo;This isn&amp;rsquo;t the right public key to verify against!&amp;rdquo;&lt;/h2&gt;
&lt;p&gt;Womp. It actually is! Go back to part 1, and check this yourself, with a block
explorer and the independent tool I linked.&lt;/p&gt;
&lt;h2 id=&#34;the-signature-isnt-actually-valid&#34;&gt;&amp;ldquo;The signature isn&amp;rsquo;t actually valid!&amp;rdquo;&lt;/h2&gt;
&lt;p&gt;Womp womp. The two packages are picked are as legit as they come!&lt;/p&gt;
&lt;h2 id=&#34;the-signature-isnt-actually-new&#34;&gt;&amp;ldquo;The signature isn&amp;rsquo;t actually new!&amp;rdquo;&lt;/h2&gt;
&lt;p&gt;Womp, womp, womp. I even built a tool to generate Satoshi signatures on demand! Check this out: &lt;a href=&#34;https://arnaudbrousseau.com/labs/satoshi-signatures&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Satoshi signatures&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;hold-on-where-is-the-private-key&#34;&gt;&amp;ldquo;Hold on. Where is the private key?!&amp;hellip;&amp;rdquo;&lt;/h2&gt;
&lt;p&gt;Warmer. Now you&amp;rsquo;re probably wondering how I&amp;rsquo;m able to produce signatures without a private key. If
you look at the &lt;a href=&#34;http://localhost:1313/labs/satoshi-signatures/satoshi-signatures.js&#34;&gt;source code for
it&lt;/a&gt;
(specifically, the &lt;code&gt;makeSignature&lt;/code&gt; function), there&amp;rsquo;s indeed no sign of the private
key! How can it be?&lt;/p&gt;
&lt;h2 id=&#34;the-hash-is-constructed-artificially&#34;&gt;&amp;ldquo;The hash is constructed artificially!&amp;rdquo;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Bingo!&lt;/strong&gt; You got it. This script implements what&amp;rsquo;s known as an &lt;a href=&#34;https://en.wikipedia.org/wiki/Digital_signature_forgery#Existential_forgery&#34;&gt;existential
forgery&lt;/a&gt;
attack. We can carefully construct a hash and the associated signature such
that they&amp;rsquo;re considered valid under the verification procedure.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/RustCrypto/traits/issues/1323#issuecomment-1587803872&#34;&gt;This
comment&lt;/a&gt;
runs through the math behind it. &lt;a href=&#34;https://arnaudbrousseau.com/labs/satoshi-signatures&#34;
target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;This demo app&lt;/a&gt; implements it, because I
needed to convince myself that it works for real!&lt;/p&gt;
&lt;h2 id=&#34;so-you-didnt-really-produce-a-message-signature-did-you&#34;&gt;&amp;ldquo;So you didn&amp;rsquo;t really produce a message signature did you?&amp;rdquo;&lt;/h2&gt;
&lt;p&gt;You&amp;rsquo;re fast! That&amp;rsquo;s exactly it. The constructed hashes are meaningless, and I&amp;rsquo;d
be hard-pressed to find a pre-image for any of them: hash functions are by
definition &lt;strong&gt;pre-image resistant&lt;/strong&gt;!&lt;/p&gt;
&lt;p&gt;In other words I shouldn&amp;rsquo;t be able to find a message
such that &lt;code&gt;hash(message) = H&lt;/code&gt; for any given constructed hash.&lt;/p&gt;
&lt;h2 id=&#34;nice-so-its-all-good-ecdsa-isnt-broken&#34;&gt;&amp;ldquo;Nice. So it&amp;rsquo;s all good? ECDSA isn&amp;rsquo;t broken?&amp;rdquo;&lt;/h2&gt;
&lt;p&gt;All good indeed, &lt;strong&gt;as long as hashing is part of the verification procedure&lt;/strong&gt;!
Verifiers, never forget: hash before verifying!&lt;/p&gt;
&lt;h2 id=&#34;what-about-other-signature-schemes&#34;&gt;&amp;ldquo;What about other signature schemes?&amp;rdquo;&lt;/h2&gt;
&lt;p&gt;Good question. All signature schemes which use hash functions as &lt;a href=&#34;https://en.wikipedia.org/wiki/Random_oracle&#34;&gt;Random
Oracles&lt;/a&gt; are vulnerable to this. I
focused on ECDSA to demonstrate a concrete forgery. Schnorr, RSA, ElGamal,
and probably many more digital signature schemes out there are vulnerable: if
hashing isn&amp;rsquo;t performed during signature verification, the Random Oracle
assumption flies out the window!&lt;/p&gt;
&lt;h1 id=&#34;moral-of-the-story&#34;&gt;Moral of the story&lt;/h1&gt;
&lt;p&gt;We&amp;rsquo;ve seen that verifying a signature against a digest (without computing it
yourself) breaks a fundamental ECDSA assumption. Specifically, it breaks the
&lt;em&gt;Random Oracle&lt;/em&gt; assumption. The output of a hash function is assumed to be
unpredictable; by constructing hash values artificially we broke this
assumption, and ECDSA verification fell apart as a result.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;re working with cryptography libraries, it&amp;rsquo;s easy to make this mistake
by accident and allow verification logic to accept arbitrary digests as input:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/paulmillr/noble-curves&#34;&gt;&lt;code&gt;@noble/curves&lt;/code&gt;&lt;/a&gt;&amp;rsquo;s default
behavior for &lt;code&gt;verify&lt;/code&gt; is to avoid hashing the message!&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/tlsfuzzer/python-ecdsa/&#34;&gt;&lt;code&gt;python-ecdsa&lt;/code&gt;&lt;/a&gt; is one-step
better: &lt;code&gt;verify&lt;/code&gt; hashes the message. However &lt;code&gt;verify_digest&lt;/code&gt; doesn&amp;rsquo;t, and
sound just as legitimate!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is not talked about widely enough. I learned about this &amp;ldquo;gotcha&amp;rdquo; a few
weeks ago after many years working in crypto. The trigger? &lt;a href=&#34;https://github.com/RustCrypto/traits/blob/3be350f2d482f8b275b66e1d40a96afc0724f050/signature/src/hazmat.rs#L64-L68&#34;&gt;A comment in the
excellent &lt;code&gt;RustCrypto/traits&lt;/code&gt;
crate&lt;/a&gt;
piqued my interest:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
/// # ⚠️ Security Warning
///
/// If `prehash` is something other than the output of a cryptographically
/// secure hash function, an attacker can potentially forge signatures by
/// solving a system of linear equations.
&lt;/pre&gt;
&lt;p&gt;I asked for clarifications with &lt;a href=&#34;https://github.com/RustCrypto/traits/issues/1323&#34;&gt;a new Github
issue&lt;/a&gt;, the maintainer
replied within a couple of hours (❤️), and I learned something valuable that day.
Now that you&amp;rsquo;ve read this, I hope the same is true for you!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;center&gt;Moral of the story: never verify without hashing first.&lt;/center&gt;&lt;/strong&gt;&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Merge Hangover</title>
      <link>https://arnaudbrousseau.com/notes/merge-hangover.html</link>
      <pubDate>Wed, 23 Nov 2022 17:38:22 -0500</pubDate>
      <guid>https://arnaudbrousseau.com/notes/merge-hangover.html</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve been running my own Ethereum validator since the Beacon Chain&amp;rsquo;s genesis,
on December 1st, 2020.&lt;/p&gt;
&lt;p&gt;22 months later, on September 15th, 2022, at block
&lt;a href=&#34;https://etherscan.io/block/15537393&#34;&gt;#15537393&lt;/a&gt;, the main proof-of-work chain
&lt;a href=&#34;https://someresat.medium.com/guide-to-staking-on-ethereum-ubuntu-prysm-581fb1969460&#34;&gt;merged&lt;/a&gt;
with the Beacon Chain, transitioning Ethereum to Proof-of-Stake fully.&lt;/p&gt;
&lt;p&gt;The world celebrated a 99.95% drop in Ethereum&amp;rsquo;s energy consumption and no
downtime during this upgrade. Meanwhile my validator started to miss all
attestations and get penalized for it:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/merge-hangover-income-flip.png&#34; alt=&#34;The Merge&#34;&gt;&lt;/p&gt;
&lt;p&gt;Time to panic.&lt;/p&gt;
&lt;h1 id=&#34;what-broke&#34;&gt;What broke?&lt;/h1&gt;
&lt;p&gt;Looking back, I should&amp;rsquo;ve seen this coming. I was running my validator and
beacon node on a hosted &lt;a href=&#34;https://www.ovhcloud.com/en/vps/&#34;&gt;VPS&lt;/a&gt;, and using
&lt;a href=&#34;https://www.infura.io/&#34;&gt;Infura&lt;/a&gt; to get access to a synced Ethereum node. This
was fine before the Merge because the beacon node only needed to talk to Infura
every once in a while to detect
&lt;a href=&#34;https://etherscan.io/address/0x00000000219ab540356cBB839Cbe05303d7705Fa&#34;&gt;contract&lt;/a&gt;
deposits.&lt;/p&gt;
&lt;p&gt;When The Merge happened, this stopped working. Validators have to assume the
duties of former proof-of-work miners. After the merge, validators propose
blocks containing user transactions.  In order to do this, a Beacon node (also
called &amp;ldquo;Consensus Layer&amp;rdquo;, or CL for short) and an Ethereum node (also called
&amp;ldquo;Execution Layer&amp;rdquo;, or EL for short) collaborate in a tight loop:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;EL needs CL to know which block is coming next&lt;/li&gt;
&lt;li&gt;CL needs EL to gather information about balances, accounts, and transactions&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Hence why Infura or other SaaS providers can&amp;rsquo;t assume that responsibility. The
&lt;a href=&#34;https://github.com/ethereum/execution-apis/blob/main/src/engine/specification.md#structures&#34;&gt;Engine
API&lt;/a&gt;
couples CL and EL clients 1-to-1, introducing a cyclic dependency
between them.&lt;/p&gt;
&lt;h1 id=&#34;why-didnt-i-see-this-coming&#34;&gt;Why didn&amp;rsquo;t I see this coming?&lt;/h1&gt;
&lt;p&gt;This new requirement (&amp;ldquo;stakers need to run their own execution client&amp;rdquo;) went
way over my head until the Merge happened. I was (still am!) in the Prysm discord,
updating my beacon &amp;amp; validator clients diligently when updates are announced. Before the merge I added a &lt;a href=&#34;https://docs.prylabs.network/docs/execution-node/fee-recipient&#34;&gt;suggested fee
recipient&lt;/a&gt; to
my validator because it caused a warning in logs. But I missed the biggest task and forgot to run my own EL client.&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s really no excuse, the writing was on the wall:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://ethereum.org/en/upgrades/merge/#preparing-for-the-merge&#34;&gt;Official Ethereum
page&lt;/a&gt;: &amp;ldquo;Run
both a consensus client and an execution client; third-party endpoints to
obtain execution data no longer work since The Merge.&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://docs.prylabs.network/docs/prepare-for-merge&#34;&gt;Prysm&amp;rsquo;s guide&lt;/a&gt; says
&amp;ldquo;You &lt;strong&gt;do&lt;/strong&gt; need to run an execution client. You &lt;strong&gt;can&amp;rsquo;t&lt;/strong&gt; use Infura as an
execution endpoint provider.&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://docs.teku.consensys.net/en/latest/HowTo/Prepare-for-The-Merge/&#34;&gt;Teku&amp;rsquo;s
guide&lt;/a&gt;:
&amp;ldquo;Service providers that provide execution layer access, such as Infura, won’t
be adequate for a beacon node to continue to function on the network&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.reddit.com/r/ethstaker/comments/rvxdue/stakers_get_ready_to_run_your_own_execution_client/&#34;&gt;/r/ethstaker&lt;/a&gt;:
&amp;ldquo;you will need to run your own execution client&amp;rdquo;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;hellip;I still got caught by surprise, somehow.&lt;/p&gt;
&lt;h1 id=&#34;vps-out-of-disk-space&#34;&gt;VPS? Out of Disk Space&lt;/h1&gt;
&lt;p&gt;To get back online as quickly as possible I thought about installing and
running an EL client on my existing VPS. Simple. Right? Wrong. My VPS provider
allowed me to purchase a 1TB disk, not more. I tried anyway and predictably ran
out of disk space while syncing. &amp;ldquo;Predictably&amp;rdquo;, given &lt;code&gt;geth&lt;/code&gt;&amp;rsquo;s &lt;a href=&#34;https://etherscan.io/chartsync/chaindefault&#34;&gt;chain data
size&lt;/a&gt; is around 1Gb these days.&lt;/p&gt;
&lt;h1 id=&#34;geth-on-ebs-out-of-disk-io&#34;&gt;Geth on EBS? Out of Disk I/O&lt;/h1&gt;
&lt;p&gt;The next thing I tried: go to AWS and rent an EC2 Ubuntu instance. I picked
&lt;code&gt;m5.xlarge&lt;/code&gt;: 16Gb of memory, with a 2TB
&lt;a href=&#34;https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AmazonEBS.html&#34;&gt;EBS&lt;/a&gt;
volume attached, and a 10Gb network link. Not bad I thought!&lt;/p&gt;
&lt;p&gt;Unfortunately, &lt;code&gt;geth&lt;/code&gt; requires fast access to disk, especially during its
initial sync. I learned this the hard way: my node was not syncing, or syncing
very slowly to the point where it&amp;rsquo;d have taken weeks or months to catch up.&lt;/p&gt;
&lt;p&gt;While looking into this problem I came across &lt;a href=&#34;https://github.com/ethereum/go-ethereum/issues/23191&#34;&gt;this github
issue&lt;/a&gt;, and specifically
&lt;a href=&#34;https://github.com/ethereum/go-ethereum/issues/23191#issuecomment-1250154156&#34;&gt;this
comment&lt;/a&gt;:
&amp;ldquo;Try erigon, they don&amp;rsquo;t have these SSD requirements&amp;rdquo;. Aha! Could it be?&lt;/p&gt;
&lt;h1 id=&#34;erigon-out-of-memory&#34;&gt;Erigon? Out of Memory&lt;/h1&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/ledgerwatch/erigon&#34;&gt;Erigon&lt;/a&gt; seemed like a better,
less-bloated client: smaller community, tighter codebase, also written in
Golang. I had a false start: Erigon, by default, starts up as a full archive
node. After a bit of research I found a decent pruning configuration (it&amp;rsquo;s &lt;a href=&#34;https://github.com/ledgerwatch/erigon/issues/3658&#34;&gt;not
that simple&lt;/a&gt;):&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
/home/ubuntu/erigon/build/bin/erigon \
    --torrent.download.rate=20mb \
    --http \
    --http.port 8545 \
    --http.api &#39;eth,web3,net,debug,trace,txpool&#39; \
    --authrpc.jwtsecret /home/ubuntu/config/jwt.hex \
    --prune=htc \
    --prune.h.older=90000 \
    --prune.t.older=90000 \
    --prune.c.older=90000 \
    --private.api.addr=localhost:9090
&lt;/pre&gt;
&lt;p&gt;This worked: my Erigon node did (eventually, after a couple of weeks!) catch up
to the chain tip, but required a ton of baby-sitting because of out-of-memory
errors. This often meant I had to manually restart my CL and EL clients.&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
Sep 23 14:09:19 ip-172-31-16-253 systemd[1]: erigon.service: Failed with result &#39;oom-kill&#39;.
Sep 23 14:09:19 ip-172-31-16-253 systemd[1]: erigon.service: Main process exited, code=killed, status=9/KILL
Sep 23 14:09:18 ip-172-31-16-253 systemd[1]: erigon.service: A process of this unit has been killed by the OOM killer.
&lt;/pre&gt;
&lt;p&gt;Unfortunately, these OOM errors persisted even after the initial sync. The
reliability of this setup was poor: during 3 weeks, on any given day, it was a
coin flip on whether I&amp;rsquo;d make money or lose money:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/merge-hangover-reliability-issues.png&#34; alt=&#34;The Merge&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;aws-out-of-money&#34;&gt;AWS? Out of Money&lt;/h2&gt;
&lt;p&gt;Outside of reliability issues caused by out-of-memory crashes, I was worried
about the price of this AWS setup. Looking at my monthly charges I&amp;rsquo;d spent
~$300 on EC2 and associated costs (EBS, bandwidth):&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/merge-hangover-aws-charges.png&#34; alt=&#34;The Merge&#34;&gt;&lt;/p&gt;
&lt;p&gt;Clearly unsustainable. The expected income for a solo staker is ~0.003
ETH per day. This translates to ~$12-$15 / month at the current ETH prices. I&amp;rsquo;m
not in this for the money, but I&amp;rsquo;m not willing to lose hundreds of dollars a
month to AWS.&lt;/p&gt;
&lt;h2 id=&#34;home-sweet-home&#34;&gt;Home? Sweet Home.&lt;/h2&gt;
&lt;p&gt;I ended up re-purposing an &lt;a href=&#34;https://www.intel.com/content/www/us/en/products/details/nuc.html&#34;&gt;Intel
NUC&lt;/a&gt; desktop
I wasn&amp;rsquo;t really using. I reformatted its 2TB SSD, installed a fresh Ubuntu on
it, and ran &lt;code&gt;geth&lt;/code&gt; + &lt;code&gt;prysm&lt;/code&gt; on it.&lt;/p&gt;
&lt;p&gt;In less than 72hrs I was caught up to the chain tip. I haven&amp;rsquo;t suffered from
reliability issues since.&lt;/p&gt;
&lt;p&gt;One thing to note if you&amp;rsquo;re trying to sync from scratch: use Checkpoint Sync
(provider list
&lt;a href=&#34;https://eth-clients.github.io/checkpoint-sync-endpoints/&#34;&gt;here&lt;/a&gt;) to let &lt;code&gt;geth&lt;/code&gt;
sync without waiting on your beacon node. Concretely, add the following to your
beacon node start command:
&lt;code&gt;--checkpoint-sync-url=https://sync-mainnet.beaconcha.in&lt;/code&gt; (or any other Checkpoint Sync provider you trust)&lt;/p&gt;
&lt;h1 id=&#34;looking-forward&#34;&gt;Looking forward&lt;/h1&gt;
&lt;p&gt;I&amp;rsquo;m quite happy to have my ETH validator humming along next to me, with no
reliance on AWS or my former VPS provider. We&amp;rsquo;ll see how reliable this setup is
long-term.&lt;/p&gt;
&lt;p&gt;Going through this made me realize that being offline as a validator isn&amp;rsquo;t
&lt;em&gt;that&lt;/em&gt; costly. ETH staking was engineered with solo stakers in mind. The
penalty for missing an attestation has the same amount than the reward for
successfully attesting.&lt;/p&gt;
&lt;p&gt;After doing some more research it seems possible to run an EL+CL combo on
cheap hardware. This is what &lt;a href=&#34;https://www.allnodes.com/&#34;&gt;AllNodes&lt;/a&gt; claim. I&amp;rsquo;m
also interested to see what &lt;a href=&#34;https://unpool.fi/&#34;&gt;Unpool.fi&lt;/a&gt; does: as a solo
staker, I&amp;rsquo;d love to use their upcoming EL+CL API as a crutch when I perform
maintenance on my own node.&lt;/p&gt;
&lt;p&gt;Thanks for reading, and good luck out there!&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Lightning Network: 7 &#34;Aha!&#34; moments to make it click</title>
      <link>https://arnaudbrousseau.com/notes/lightning-network-aha-moments.html</link>
      <pubDate>Sun, 28 Aug 2022 11:40:52 -0500</pubDate>
      <guid>https://arnaudbrousseau.com/notes/lightning-network-aha-moments.html</guid>
      <description>&lt;p&gt;I recently finished reading &lt;em&gt;Mastering the Lighning Network&lt;/em&gt; (&lt;a href=&#34;https://www.amazon.com/Mastering-Lightning-Network-Blockchain-Protocol-dp-1492054860/dp/1492054860/&#34;&gt;Amazon
link&lt;/a&gt;, &lt;a href=&#34;https://github.com/lnbook/lnbook&#34;&gt;Github link&lt;/a&gt;). This book does a great job
explaining the design of the Lightning Network and the details of the protocol.
I had a few &amp;ldquo;Aha!&amp;rdquo; moments while reading it and I&amp;rsquo;d like to share them with
you!&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;center&gt;&lt;small&gt;
To get the most out of this note, no prior knowledge about the Lightning
Network is required, but a basic understanding of Bitcoin&amp;rsquo;s UTXO model and
scripting capability is.
&lt;/small&gt;&lt;/center&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h1 id=&#34;aha-a-true-peer-to-peer-network&#34;&gt;Aha! A true peer-to-peer network!&lt;/h1&gt;
&lt;p&gt;The Bitcoin network is famously &amp;ldquo;A Peer-to-Peer Electronic Cash System&amp;rdquo; (this
is in the title of the &lt;a href=&#34;https://bitcoin.org/bitcoin.pdf&#34;&gt;Bitcoin whitepaper&lt;/a&gt;!). However,
participants are split in practice:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Miners commit transactions to the Bitcoin ledger with new blocks&lt;/li&gt;
&lt;li&gt;Non-mining nodes accept new transactions in their mempools and relay gossip&lt;/li&gt;
&lt;li&gt;Light clients or simple &amp;ldquo;users&amp;rdquo; of Bitcoin connect to node providers to get
data and broadcast new transactions&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/lightning-network-types.png&#34; alt=&#34;Network types&#34;&gt;&lt;/p&gt;
&lt;p&gt;The Lightning Network, however, is only composed of peer-to-peer relationships
called &lt;strong&gt;channels&lt;/strong&gt;. Channels are the pathways of the network, through which
payments travel. All participants must open at least one channel to another
participant to send and receive payments. The network is a &lt;a href=&#34;https://1ml.com/visual/network&#34;&gt;big, amorphous
graph&lt;/a&gt; of participants connected to each other
with channels, all on the same level.&lt;/p&gt;
&lt;h1 id=&#34;aha-transfers-are-lightning-fast-becausethere-are-no-transfers&#34;&gt;Aha! Transfers are &amp;ldquo;lightning&amp;rdquo; fast because&amp;hellip;there are no transfers!&lt;/h1&gt;
&lt;p&gt;Surprise: the protocol outlined in the Lightning Network standards
(&lt;a href=&#34;https://github.com/lightning/bolts/blob/master/00-introduction.md&#34;&gt;&amp;ldquo;BOLTS&amp;rdquo;&lt;/a&gt;) does not define value transfer. At its core, the Lightning
Network is a protocol for two participants to pool funds together and make
commitments to splitting this fund pool. This split evolves over time, enabling
&amp;ldquo;transfers&amp;rdquo;. For example, say I want to send you 0.5 BTC through a channel you
and I have opened. At the moment there is 1 BTC on my side and 2 BTC on yours.
If we both agree to split 0.5 BTC / 2.5 BTC instead of currently 1 BTC / 2 BTC,
the transfer is done!&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s easy to understand why these kinds of transfers are wicked fast: they&amp;rsquo;re
not actually happening. Only commitments are exchanged between participants.&lt;/p&gt;
&lt;h1 id=&#34;aha-funds-are-pooled-via-multisig-with-pre-signed-transactions-as-insurance&#34;&gt;Aha! Funds are pooled via multisig, with pre-signed transactions as insurance!&lt;/h1&gt;
&lt;p&gt;You&amp;rsquo;re probably wondering how commitments actually work. It seems magic.
Participants cannot trust each other, making this a hard problem. The Lightning
Network solves this by pooling funds through multisig, and committing with
pre-signed Bitcoin transactions.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Pooling&lt;/strong&gt;. Pooling funds is done through a Bitcoin primitive you probably
know already: &lt;a href=&#34;https://en.bitcoin.it/wiki/Multi-signature&#34;&gt;multisig&lt;/a&gt;. Opening a
Lightning channel is equivalent to funding a &amp;ldquo;2-out-of-2&amp;rdquo; multisig
address. If you and I deposit funds into a 2-out-of-2 address, neither of us
can unilateraly move these funds. That&amp;rsquo;s good but: how can I get my money back
if you lose your key or go offline? What if you never agree to sign a
transaction even when I&amp;rsquo;m just taking my fair share? This is where pre-signed
Bitcoin transactions (also called &amp;ldquo;commitment transactions&amp;rdquo;) come in.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Committing&lt;/strong&gt;. Agreeing on who owns what share of the fund pool is done via
&lt;em&gt;pre-signed&lt;/em&gt; offline Bitcoin transactions. These transactions are called
&amp;ldquo;commitment transactions&amp;rdquo;, or &amp;ldquo;commitments&amp;rdquo; for short. They spend funds out of
the multisig address and split them across the two channel partners. They
provide an important guarantee: in case things go wrong, the commitment
transactions can be broadcast and funds are sent out of the multisig address,
back to the channel partners, according to the agreed upon split. Therefore,
it&amp;rsquo;s crucial to put this guarantee in place before sending funds to the
multisig address! &lt;small&gt;(if you&amp;rsquo;re wondering how that&amp;rsquo;s possible, the next section on
SegWit has answers for you!)&lt;/small&gt;&lt;/p&gt;
&lt;p&gt;How are commitments put in place? Well, here are the messages exchanged to open
a Lightning channel:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;[&lt;a href=&#34;https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-open_channel-message&#34;&gt;&lt;code&gt;open_channel&lt;/code&gt;&lt;/a&gt;] &amp;ldquo;Hey, I want to open a channel with you, you down?&amp;rdquo;&lt;/li&gt;
&lt;li&gt;[&lt;a href=&#34;https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-accept_channel-message&#34;&gt;&lt;code&gt;accept_channel&lt;/code&gt;&lt;/a&gt;] &amp;ldquo;Sure, sounds good to me!&amp;rdquo;&lt;/li&gt;
&lt;li&gt;[&lt;a href=&#34;https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-funding_created-message&#34;&gt;&lt;code&gt;funding_created&lt;/code&gt;&lt;/a&gt;] &amp;ldquo;Before I sent funds to this new
multisig address, mind signing this commitment transaction? That way I can
get my money back if things go wrong.&amp;rdquo;&lt;/li&gt;
&lt;li&gt;[&lt;a href=&#34;https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-funding_signed-message&#34;&gt;&lt;code&gt;funding_signed&lt;/code&gt;&lt;/a&gt;] &amp;ldquo;Here you go!&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;The channel opener send funds to the multisig address as promised.
Meanwhile, the other partner monitors on-chain for confirmations&amp;hellip;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;[&lt;a href=&#34;https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-channel_ready-message&#34;&gt;&lt;code&gt;channel_ready&lt;/code&gt;&lt;/a&gt;] &amp;ldquo;Nice! I now see enough confirmations on
this funding transaction. We&amp;rsquo;re in business!&amp;rdquo;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When a channel is open, 100% of the funds are allocated to the channel opener.
To update the channel balance old commitments are revoked, and a new one
established.&lt;/p&gt;
&lt;h1 id=&#34;aha-segwit-enables-offline-chaining-of-signed-transactions&#34;&gt;Aha! SegWit enables offline chaining of signed transactions!&lt;/h1&gt;
&lt;p&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/SegWit&#34;&gt;SegWit&lt;/a&gt; solves the &lt;a href=&#34;https://en.bitcoin.it/wiki/Transaction_malleability&#34;&gt;transaction malleability&lt;/a&gt; problem. Before SegWit
signatures (aka &amp;ldquo;witnesses&amp;rdquo;) were part of the data hashed to produce
transaction identifiers. This meant that the transaction hash (or ID) could
change if the signature bytes changed. Given signatures aren&amp;rsquo;t deterministic
(signers can pick different nonces, observers can also flip the &amp;ldquo;s&amp;rdquo; value or
play with DER encoding to get the same signature encoded with different
bytes), it was not safe to expect that a signed, off-chain transaction
would keep its ID. The only safe way to get a reliable transaction ID was to
broadcast it on-chain. As a result chaining signed transactions without
broadcasting them was risky.&lt;/p&gt;
&lt;p&gt;SegWit solves this by excluding (or, &lt;strong&gt;seg&lt;/strong&gt;regating) signatures (or,
&lt;strong&gt;wit&lt;/strong&gt;nesses) from the data hashed to produce a transaction ID. As a result, a
change in the signature won&amp;rsquo;t change the transaction ID. This is why it&amp;rsquo;s safe
to rely on this ID to construct another transaction using it, even if it&amp;rsquo;s not
broadcast on-chain.&lt;/p&gt;
&lt;p&gt;This is fundamental for the Lightning network since commitment transactions
(remember, they&amp;rsquo;re our &amp;ldquo;insurance&amp;rdquo;) have to be signed before funding
transactions are broadcast, yet commitment transactions need the funding
transaction ID to be constructed. In other words, the Lightning Network would
not be able to function without SegWit and offline transaction chaining.&lt;/p&gt;
&lt;h1 id=&#34;aha-bitcoin-script-and-game-theory-to-harden-commitment-outputs&#34;&gt;Aha! Bitcoin script and game theory to harden commitment outputs!&lt;/h1&gt;
&lt;p&gt;To update the channel balances, old commitments need to be revoked and a new one
established. This is done with a simple exchange of messages:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#committing-updates-so-far-commitment_signed&#34;&gt;&lt;code&gt;commitment_signed&lt;/code&gt;&lt;/a&gt;
contains a new partially signed commitment (missing the recipient&amp;rsquo;s signature)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#completing-the-transition-to-the-updated-state-revoke_and_ack&#34;&gt;&lt;code&gt;revoke_and_ack&lt;/code&gt;&lt;/a&gt; acknowledges the commitment and revokes
the last valid one&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Commitment transactions are sophisticated, to prevent cheating. The idea is
that if I cheat by broadcasting an old commitment, you should have some time to
react and punish me. In practice this is implemented with revocation secrets:
when revealed they let the other party redeem a &amp;ldquo;punishment&amp;rdquo; output, taking the
other party&amp;rsquo;s share. That&amp;rsquo;s the financial incentive not to broadcast old
commitments.&lt;/p&gt;
&lt;p&gt;In order to implement punishment, commitments are non-symmetrical. The
&amp;ldquo;punishment&amp;rdquo; outputs have different amounts and beneficiaries: you can punish me
and claim my share if I broadcast an old commitment of mine to you, and I can
punish you and take your share if you broadcast an old commitment of yours to me.&lt;/p&gt;
&lt;p&gt;To allow for cheating detection and enforcement, commitments output are delayed
so that the party crafting them is forced to wait for a window of time to get
their fair share. This is to ensure the other party has time to detect cheating
and use their revocation secret if they so choose. The time delay is not
dictated by the protocol: it is agreed upon when the channel is open
(&lt;code&gt;to_self_delay&lt;/code&gt; in &lt;a href=&#34;https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-open_channel-message&#34;&gt;&lt;code&gt;open_channel&lt;/code&gt;&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;To illustrate this, let&amp;rsquo;s take a concrete example. If A and B have a
channel opened (split with 0.5 BTC for A, and 2.5 BTC for B), here are the
commitment transactions on each side:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/lightning-commitments.png&#34; alt=&#34;Commitment transactions&#34;&gt;&lt;/p&gt;
&lt;p&gt;This looks complicated but the Bitcoin script to implement this is surprisingly
simple. Below is the Bitcoin script for the &amp;ldquo;either/or&amp;rdquo; fork for A&amp;rsquo;s commitment
to B:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
OP_IF
    # revocation secret can spend the funds immediately if A cheats
    revocation_pubkey
OP_ELSE
    # This Bitcoin OP is defined
    # in BIP 112: https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki
    # It ensures the current output can&#39;t be spent before time_delay
    time_delay OP_CHECKSEQUENCE_VERIFY OP_DROP

    # If the line above succeeds (gets off the stack with `OP_DROP`),
    # public_key_for_A is able to spend the funds.
    # This only happens after a delay because of OP_CHECKSEQUENCE_VERIFY
    public_key_for_A
OP_ENDIF
# Checks signature for either revocation_pubkey or public_key_for_A
OP_CHECKSIG
&lt;/pre&gt;
&lt;p&gt;There you have it, game theory and Bitcoin primitives coming together in this
commitment transaction output!&lt;/p&gt;
&lt;p&gt;Now let&amp;rsquo;s dive one layer deeper: how do revocation secrets work exactly?
Remember that revocation secrets are powerful, you can claim my portion of the
channel balance with it! How are they generated and how do they &amp;ldquo;revoke&amp;rdquo;
commitments exactly?&lt;/p&gt;
&lt;h1 id=&#34;aha-revoking-a-commitment-is-done-by-revealing-a-secret&#34;&gt;Aha! Revoking a commitment is done by revealing a secret!&lt;/h1&gt;
&lt;p&gt;Revocation secret derivation is explained precisely in &lt;a href=&#34;https://github.com/lightning/bolts/blob/master/03-transactions.md#revocationpubkey-derivation&#34;&gt;BOLT#3&lt;/a&gt;. However
the technical nature of the spec masks the cleverness of its design. Let&amp;rsquo;s walk
through it together!&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Warning: this requires some knowledge of elliptic curve cryptography.&lt;/em&gt;&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;Click/Tap for a quick primer.&lt;/em&gt;&lt;/summary&gt;
Here are the important concepts to grasp:
&lt;ul&gt;
&lt;li&gt; What are elliptic curves?&lt;br&gt;
  &lt;small&gt;
  Short version: they&#39;re curves with the equation:
  &lt;code&gt;y&lt;/code&gt;&lt;sup&gt;2&lt;/sup&gt; = &lt;code&gt;x&lt;/code&gt;&lt;sup&gt;3&lt;/sup&gt; + &lt;code&gt;ax&lt;/code&gt; + &lt;code&gt;b&lt;/code&gt;. Instead of using real
  numbers, ECC computes all operations modulo a large prime number P
  &lt;/small&gt;
  &lt;/li&gt;
&lt;li&gt; What is point multiplication?&lt;br&gt;
  &lt;small&gt;
  Short version: take two points on an alliptic curve,
  find the intersection with the elliptic curve, then negate the y coordinate
  to obtain the &#34;sum&#34; point. Sum a point P with itself &lt;code&gt;x&lt;/code&gt; times and you have point
  multiplication: &lt;code&gt;x*P&lt;/code&gt;!
  &lt;/small&gt;
  &lt;/li&gt;
&lt;li&gt; How do public and private keys relate to elliptic curve points&lt;br&gt;
  &lt;small&gt;
  Short version: private keys are just big integers. Public keys are points on
  the elliptic curve. A public key or point is obtained by point
  multiplication: &lt;code&gt;pubkey = n*G&lt;/code&gt;, where &lt;code&gt;n&lt;/code&gt; is the private key and &lt;code&gt;G&lt;/code&gt; is the
  generator of the curve; &lt;code&gt;G&lt;/code&gt; is arbitrarily chosen
  &lt;/small&gt;
  &lt;/li&gt;
&lt;p&gt;If you want more details on ECC with awesome visuals, I highly recommend
reading &lt;a href=&#34;https://curves.xargs.org/&#34;&gt;The Animated Elliptic Curve&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Back to the lightning network and revocation secrets!&lt;/p&gt;
&lt;/details&gt;
&lt;p&gt;If two parties (let&amp;rsquo;s call them &amp;ldquo;A&amp;rdquo; and &amp;ldquo;B&amp;rdquo;) open a channel, they exchange two
(public) elliptic curve points as part of the flow: &lt;code&gt;revocation_basepoint&lt;/code&gt; and
&lt;code&gt;per_commitment_point&lt;/code&gt;. Revocation public keys (&lt;code&gt;revocation_pubkey&lt;/code&gt;) are
composed from these two points:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/lightning-ecc-trick.png&#34; alt=&#34;ECC trick&#34;&gt;&lt;/p&gt;
&lt;p&gt;To make the shared point deterministic, the Lightning Network picks &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt;
based on values known to both parties:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
revocation_pubkey = 
    revocation_basepoint
      * sha256(revocation_basepoint || per_commitment_point)
  + per_commitment_point
      * sha256(per_commitment_point || revocation_basepoint)
&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;(In the above, &lt;code&gt;||&lt;/code&gt; represents byte concatenation and &lt;code&gt;*&lt;/code&gt; is ECC point
multiplication)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The associated private key is given by:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
revocation_privkey = 
    revocation_secret
        * sha256(revocation_basepoint || per_commitment_point)
  + per_commitment_secret
        * sha256(per_commitment_point || revocation_basepoint)
&lt;/pre&gt;
&lt;p&gt;To convince yourself that this works, multiply the above expression
by &lt;code&gt;G&lt;/code&gt; and you&amp;rsquo;ll find that &lt;code&gt;revocation_privkey * G&lt;/code&gt; results in &lt;code&gt;revocation_pubkey&lt;/code&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;Click/Tap to reveal proof&lt;/summary&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
G * revocation_privkey
= G * (
    revocation_secret
        * sha256(revocation_basepoint || per_commitment_point)
    + per_commitment_secret
        * sha256(per_commitment_point || revocation_basepoint)
  )
= G * revocation_secret
  ^-------------------^ this is revocation_basepoint!
        * sha256(revocation_basepoint || per_commitment_point)
  + G * per_commitment_secret 
  ^-------------------------^ this is per_commitment_point!
      * sha256(per_commitment_point || revocation_basepoint)
= revocation_basepoint
      * sha256(revocation_basepoint || per_commitment_point)
  + per_commitment_point
      * sha256(per_commitment_point || revocation_basepoint)
= revocation_pubkey (Q.E.D.)
&lt;/pre&gt;
&lt;/details&gt;
&lt;p&gt;&lt;code&gt;revocation_pubkey&lt;/code&gt; can be computed by anyone since it&amp;rsquo;s composed of 2 public
points. The interesting piece is the &lt;code&gt;revocation_privkey&lt;/code&gt;, composed of two
secrets spread across channel partners: &lt;code&gt;revocation_secret&lt;/code&gt; and
&lt;code&gt;per_commitment_secret&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;revocation_secret&lt;/code&gt; is generated once upon channel opening. The associated
public point (&lt;code&gt;revocation_basepoint&lt;/code&gt;) stays the same during the lifetime of
the channel.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;per_commitment_secret&lt;/code&gt; values are specific to each commitment. &lt;br&gt;&lt;small&gt;To make this
fast, they&amp;rsquo;re based on a single seed computed at the beginning. The
derivation of subsequent secrets (one for each commitment) is explained in
&lt;a href=&#34;https://github.com/lightning/bolts/blob/master/03-transactions.md#per-commitment-secret-requirements&#34;&gt;BOLT#3: Per-commitment Secret Requirements&lt;/a&gt;&lt;/small&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It turns out &amp;ldquo;revoking&amp;rdquo; a commitment is the act of &lt;em&gt;revealing its
per-commitment secret&lt;/em&gt;. The reveal is done with a field named
&lt;code&gt;per_commitment_secret&lt;/code&gt; in the &lt;a href=&#34;https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#completing-the-transition-to-the-updated-state-revoke_and_ack&#34;&gt;&lt;code&gt;revoke_and_ack&lt;/code&gt;&lt;/a&gt; message. This
message also contains &lt;code&gt;next_per_commitment_point&lt;/code&gt; such that the other party can
compute the next &lt;code&gt;revocation_pubkey&lt;/code&gt; and use it to craft the next commitment
transaction. To make this more concrete, let&amp;rsquo;s illustrate this with our 2
channel partners, A and B:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A generates a &lt;code&gt;revocation_basepoint&lt;/code&gt; during channel opening&lt;/li&gt;
&lt;li&gt;B sends &lt;code&gt;per_commitment_point_1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;A crafts commitment #1 using &lt;code&gt;revocation_basepoint&lt;/code&gt; and &lt;code&gt;per_commitment_point_1&lt;/code&gt;, and sends it to B&lt;/li&gt;
&lt;li&gt;B sends &lt;code&gt;per_commitment_secret_1&lt;/code&gt; (thereby revoking commitment #1), and sends &lt;code&gt;per_commitment_point_2&lt;/code&gt; to A&lt;/li&gt;
&lt;li&gt;A crafts commitment #2, using &lt;code&gt;revocation_basepoint&lt;/code&gt; and &lt;code&gt;per_commitment_point_2&lt;/code&gt;, and sends it to B&lt;/li&gt;
&lt;li&gt;B sends &lt;code&gt;per_commitment_secret_2&lt;/code&gt; (thereby revoking commitment #2), and sends &lt;code&gt;per_commitment_point_3&lt;/code&gt; to A&lt;/li&gt;
&lt;li&gt;&amp;hellip;and so on and so forth&lt;/li&gt;
&lt;/ul&gt;
&lt;small&gt;
Note: the above only describes how A creates commitments for B. When B wants to
create commitments for A, it uses its own &lt;code&gt;revocation_basepoint&lt;/code&gt; and
A&#39;s series of &lt;code&gt;per_commitment_point&lt;/code&gt; values.
&lt;/small&gt;
&lt;p&gt;Now it should be clear why commitment transactions never change, yet they&amp;rsquo;re
&amp;ldquo;revoked&amp;rdquo;: when the &lt;code&gt;per_commitment_secret&lt;/code&gt; for a given commitment is revealed,
the other party can suddently compute the associated &lt;code&gt;revocation_privkey&lt;/code&gt; and
redeem the commitment&amp;rsquo;s &amp;ldquo;punishment&amp;rdquo; output if it was ever broadcast on-chain.
This strong financial incentive is enough to keep old commitment transactions
offline for good.&lt;/p&gt;
&lt;h1 id=&#34;aha-multi-hop-atomic-payments-with-htlcs&#34;&gt;Aha! Multi-hop, atomic payments with HTLCs!&lt;/h1&gt;
&lt;p&gt;We&amp;rsquo;ve seen how the Lightning Network enables peer-to-peer payments. Now let&amp;rsquo;s
move to &lt;em&gt;indirect&lt;/em&gt; or &amp;ldquo;multi-hop&amp;rdquo; payments. If A has a channel open with B, and
B has a channel opened with C, can A pay C?&lt;/p&gt;
&lt;p&gt;Yes it can! Provided that there is a route with enough capacity from A to C,
not only can A pay C, it can do so &lt;em&gt;atomically&lt;/em&gt;. Either all legs of the payment
(e.g. &lt;code&gt;A-&amp;gt;B&lt;/code&gt;, &lt;code&gt;B-&amp;gt;C&lt;/code&gt;) succeed, or all legs fail. This is possible at scale,
even with 10, 15, or 20+ intermediary nodes. If you&amp;rsquo;re used to the traditional
financial system where intermediaries cause hard-to-debug failures and long
settlement delays&amp;hellip;isn&amp;rsquo;t this mind-blowing?&lt;/p&gt;
&lt;p&gt;The Lightning Network does this with &lt;strong&gt;Hash-Time-Lock-Contracts (&amp;ldquo;HTLCs&amp;rdquo;)&lt;/strong&gt;.
These contracts are &amp;ldquo;just&amp;rdquo; valid Bitcoin scripts. The basic premise is that an
HTLC is a contract between 2 parties (1 issuer, 1 recipient), and it enforces
the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Funds can be spent by the issuer after a period of time (expiration clause)&lt;/li&gt;
&lt;li&gt;Funds can be spent immediately by the recipient if they provide a valid
pre-image (the &amp;ldquo;pre-image&amp;rdquo; of a hash &lt;code&gt;H&lt;/code&gt; is an input &lt;code&gt;I&lt;/code&gt; which satisfies
&lt;code&gt;hash(I)=H&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Hence the name &amp;ldquo;HTLC&amp;rdquo;, HTLC contracts are Hash-locked contract from the
point-of-view of the recipient, or Time-locked contract from the point-of-view
of the issuer.&lt;/p&gt;
&lt;p&gt;How are HTLCs helping with instant, atomic payments? Here&amp;rsquo;s how a payment from
A to B to C happens in practice: &lt;br&gt;&lt;small&gt;(note: if you&amp;rsquo;re wondering
why &amp;ldquo;B&amp;rdquo; was picked as an intermediary, we&amp;rsquo;ll see later that path
discovery isn&amp;rsquo;t explicitly part of the BOLT specs! Another interesting
aspect of the Lightning Network design)&lt;/small&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;C creates a lightning &amp;ldquo;invoice&amp;rdquo; to A for 100,000 satoshis (0.001 BTC). This
could be communicated over an email, through a web-based checkout flow, via
an in-person QR code, etc.  At the core of this invoice is a hash H. The
pre-image is only known by C.&lt;/li&gt;
&lt;li&gt;A issues an HTLC to B, locking 101,000 satoshis in an HTLC output. Remember:
this HTLC can be spent by A after expiration, or by B if they provide the
correct pre-image.&lt;/li&gt;
&lt;li&gt;B issues an HTLC to C, locking 100,000 satoshis. Note the different amounts
in the HTLC issued by A (101,000 satoshis) vs. B (100,000 satoshis). The
difference (1,000 satoshis) is the fee that B collects for forwarding the
payment through its channel with C. It compensates B for the inconvenience
of locking funds temporarily.&lt;/li&gt;
&lt;li&gt;C can now get paid by redeeming the HTLC, because it knows a valid pre-image
for hash H (this pre-image was used to generate the original invoice)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/lightning-htlc.png&#34; alt=&#34;HTLC diagram: A-to-B-to-C&#34;&gt;&lt;/p&gt;
&lt;p&gt;To redeem the HTLC, C can broadcast a transaction containing a valid pre-image.
Doing this will reveal the previously secret pre-image because it&amp;rsquo;s publicly
on-chain! The public reveal of the pre-image makes all HTLCs spendable by their
recipients. In our example, B can now unlock the HTLC offered by A and redeem
101,000 satoshis.&lt;/p&gt;
&lt;p&gt;This is how atomic payments are enabled: regardless of the
number of intermediaries, either &lt;strong&gt;all&lt;/strong&gt; HTLCs become spendable when the pre-image
is publicly revealed, or &lt;strong&gt;none&lt;/strong&gt; of them do.&lt;/p&gt;
&lt;p&gt;In practice broadcasting on the Bitcoin network isn&amp;rsquo;t efficient because it
incurs fees. Instead, C can send the pre-image to B, thereby
prooving it &lt;em&gt;could&lt;/em&gt; redeem the HTLC if it wanted (by going on-chain). This
is enough for B to get comfortable and update the (B,C) channel balance,
sending 100,000 satoshis to C.&lt;/p&gt;
&lt;p&gt;Once B has updated the (B,C) channel balance, B can send the pre-image to A.
For the same reason, A prefers to settle the HTLC off-chain and send 101,000
satoshis to B through the (A,B) channel.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
For the curious reader: what&#39;s the incentive not to broadcast HTLCs on-chain
after off-chain settlement is done?
&lt;/summary&gt;
You may have noticed an incentive problem in the previous example: why would C
not broadcast the HTLC on-chain &lt;em&gt;after&lt;/em&gt; the channel balance is updated? After all, C has
the pre-image so why not take the money twice? Once from the off-chain settlement
through B&#39;s balance update, the second on-chain with the HTLC broadcast!
&lt;p&gt;To fix this, the Lightning Network incorporates HTLCs into commitment
transactions. In other words, B doesn&amp;rsquo;t simply send an HTLC to C. B and C
actually exchange &lt;em&gt;commitment transactions&lt;/em&gt; which include the HTLC as an extra output.&lt;/p&gt;
&lt;p&gt;Specifically, the commitment transaction from B to C has the following outputs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;output to B for B&amp;rsquo;s balance minus 100,000 satoshis (delayed)&lt;/li&gt;
&lt;li&gt;output to C for C&amp;rsquo;s balance (immediate)&lt;/li&gt;
&lt;li&gt;output to C for B&amp;rsquo;s balance minus 100,000 satoshis (immediate with revocation key)&lt;/li&gt;
&lt;li&gt;output to HTLC for 100,000 satoshis&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And the commitment transaction from C to B has the following outputs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;output to C for C&amp;rsquo;s balance (delayed)&lt;/li&gt;
&lt;li&gt;output to B for B&amp;rsquo;s balance - 100,000 satoshis (delayed)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;output to B for C&amp;rsquo;s balance (immediate with revocation key)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;output to HTLC for 100,000 satoshis&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When C reveals the pre-image to B and B updates the channel balance with a new
commitment, C has to send B the revocation key to revoke the previous
commitment. This means that C can&amp;rsquo;t &amp;ldquo;double claim&amp;rdquo; the HTLC: once it&amp;rsquo;s settled
off-chain, the corresponding commitment becomes obsolete. B can punish C with
the revocation key if C decides to broadcast it on-chain!&lt;/p&gt;
&lt;/details&gt;
&lt;h1 id=&#34;bonus-significance-of-taproot-upgrade-and-schnorr-signatures&#34;&gt;Bonus: Significance of Taproot upgrade and Schnorr signatures&lt;/h1&gt;
&lt;p&gt;I&amp;rsquo;ve never connected Schnorr signatures with the Lightnint Network before. The
relationship is that Schnorr signatures unlock Point Time-Locked Contracts
(PTLCs). PTLCs are &amp;ldquo;Bitcoin scripts that allows a conditional spend either on
the presentation of a secret or after a certain blockheight has passed, similar
to an HTLC. Unlike HTLCs, PTLCs do not depend on a preimage of a hash function
but rather on the private key from an elliptic curve point. The security
assumption is thus based on the discrete logarithm. PTLCs are not yet
implemented on the Lightning Network&amp;rdquo; (taken from the Mastering the Lightning
Network&amp;rsquo;s glossary)&lt;/p&gt;
&lt;h1 id=&#34;bonus-choosing-not-to-design-payment-routing&#34;&gt;Bonus: Choosing NOT to design payment routing&lt;/h1&gt;
&lt;p&gt;Designing is making choices. It&amp;rsquo;s also choosing NOT to make a choice, to leave
room for experimentation and innovation within the protocol boundary.&lt;/p&gt;
&lt;p&gt;I was a bit shocked to learn that there is no standard on how to route payments
in lightning. The probing for channel balances happens independently, through
trial and error. &lt;a href=&#34;https://arxiv.org/abs/2107.05322&#34;&gt;Some&lt;/a&gt; &lt;a href=&#34;https://arxiv.org/abs/2103.08576&#34;&gt;papers&lt;/a&gt; have
been written on how to do this independently.  There&amp;rsquo;s also, in the same
category, innovation on how to manage channel liquidity. For example:
&lt;a href=&#34;https://lightning.engineering/loop/&#34;&gt;Loop&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This is how lightning &amp;ldquo;scales&amp;rdquo;. The protocol itself doesn&amp;rsquo;t mandate anything,
actors within the lightning community are coming up with bottom-up solutions
like these, getting better and better over time.&lt;/p&gt;
&lt;h1 id=&#34;bonus-no-networking-needed&#34;&gt;Bonus: No networking needed!&lt;/h1&gt;
&lt;p&gt;Then I realized: opening payment channels, evolving commitments, and closing
channels can all be done by exchanging messages on USB drives or paper, fully
offline. These messages do not have to follow BOLT standards as long as the
structure of the commitment transactions is kept intact (validity of
transactions on-chain is key to enforcing incentives and preventing cheating).&lt;/p&gt;
&lt;p&gt;Nothing mandates a &amp;ldquo;network&amp;rdquo; for pure peer-to-peer payment to work. The design
is extremely resilient: no privileged node assumption (all nodes are
participants, all participants are nodes!), no speed or hard protocol
requirement for message exchange, and no trust assumptions even for direct
peers. Thanks to cryptography and game theory the only real assumption in
the Lightning Network is reliable access to the Bitcoin Network, to detect and
punish cheaters.&lt;/p&gt;
&lt;p&gt;This makes the design of the Lightning Network applicable broadly:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;banks or exchanges could run lightning-like protocols to send crypto back and
forth at high frequency without on-chain transactions in a trustless way.&lt;/li&gt;
&lt;li&gt;Other chains could (actually: &lt;a href=&#34;https://github.com/raiden-network/raiden&#34;&gt;already have!&lt;/a&gt;) implemented the same
ideas to power peer-to-peer payments on top of their base layer.&lt;/li&gt;
&lt;li&gt;Taro (Taproot-Native Asset Overlay) is another promising proposal to onboard
foreign assets into Lightning. To learn more, see &lt;a href=&#34;https://docs.google.com/presentation/d/1GU4dtNLdT92lzb5Z2FR-dPY88zVPg7R7tlxRKJ7uMnQ/&#34;&gt;this
presentation&lt;/a&gt; from Bitcoin 2022, &lt;a href=&#34;https://docs.lightning.engineering/the-lightning-network/taro&#34;&gt;this wiki from Lightning
Labs&lt;/a&gt;, or &lt;a href=&#34;https://river.com/learn/what-is-taro-in-bitcoin/&#34;&gt;this excellent explainer by River
Financial&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;If you&amp;rsquo;ve made it this far, thank you for reading. We&amp;rsquo;ve covered quite a lot of
ground and have seen that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the Lightning Network is a pure peer-to-peer network, unlike its base layer&lt;/li&gt;
&lt;li&gt;the Lightning Network is a way for 2 parties to exchange commitments about a
common pool of funds. It&amp;rsquo;s not (directly) about transfers!&lt;/li&gt;
&lt;li&gt;the Lightning Network cleverly mixes game theory, cryptography, and Bitcoin
primitives to guarantee participants&#39; safety&lt;/li&gt;
&lt;li&gt;the Lightning Network needs SegWit to work at all because transaction
chaining and pre-signed transactions are at the heart of commitments&lt;/li&gt;
&lt;li&gt;the Lightning Network uses HTLCs to enable atomic, multi-hop payments&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I highly recommend reading the full version of &lt;em&gt;Mastering the Lighning Network&lt;/em&gt;
(&lt;a href=&#34;https://www.amazon.com/Mastering-Lightning-Network-Blockchain-Protocol-dp-1492054860/dp/1492054860/&#34;&gt;Amazon link&lt;/a&gt;, &lt;a href=&#34;https://github.com/lnbook/lnbook&#34;&gt;Github link&lt;/a&gt;) if you&amp;rsquo;re looking
to learn more about the Lightning Network. The design principles behind it are
worth dissecting. I hope you&amp;rsquo;ll get as much satisfaction as I did while diving in!&lt;/p&gt;
&lt;center&gt;&lt;small&gt;&lt;em&gt;Thanks to Rob S. and Alex M. for their valuable feedback on previous versions of this text.&lt;/em&gt;&lt;/small&gt;&lt;/center&gt;
</description>
    </item>
    <item>
      <title>Improving as a Technical Writer</title>
      <link>https://arnaudbrousseau.com/notes/improving-as-a-technical-writer.html</link>
      <pubDate>Wed, 01 Jun 2022 09:40:34 -0500</pubDate>
      <guid>https://arnaudbrousseau.com/notes/improving-as-a-technical-writer.html</guid>
      <description>&lt;h1 id=&#34;a-brief-definition-of-technical-writing&#34;&gt;A brief definition of technical writing&lt;/h1&gt;
&lt;p&gt;Writing is an immense field. It includes poetry, short stories, journalism,
haikus. Technical writing is about &lt;strong&gt;communicating information related to
technical topics&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Improving at technical writing requires a focus on this particular type of
communication. Technical writing favors &lt;strong&gt;efficiency&lt;/strong&gt; and &lt;strong&gt;clarity&lt;/strong&gt;.&lt;/p&gt;
&lt;h1 id=&#34;why-is-technical-writing-important-to-me&#34;&gt;Why is technical writing important to me?&lt;/h1&gt;
&lt;p&gt;I immigrated to the United States (from France) in 2012 and I&amp;rsquo;ve been trying to
get to fluency in my communication ever since. Technical writing (for me) is
about making technical ideas and concepts accessible to others. It gives me an
opportunity to be heard, on a more even footing with others. I get to craft my
message more carefully that way.&lt;/p&gt;
&lt;h1 id=&#34;why-might-technical-writing-be-important-to-you&#34;&gt;Why might technical writing be important to you?&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;The software industry has recently shifted to remote-first. It forces most communication to be in written form&lt;/li&gt;
&lt;li&gt;Technical writing is the basis of &lt;strong&gt;asynchronous communication&lt;/strong&gt; for engineers. Text is async by nature: it can be consumed whenever convenient for each reader&lt;/li&gt;
&lt;li&gt;Text is universal. Can fit on all screens, terminals and programs.&lt;/li&gt;
&lt;li&gt;Writing is a powerful thinking tool! Writing forces coherent thoughts and highlights gaps. If you think you understand something, try to write about it. Writing is a Litmus test to answer &amp;ldquo;do I understand this well enough?&amp;rdquo;. More on this topic at &lt;a href=&#34;https://alistapart.com/article/writing-is-thinking/&#34;&gt;Writing is Thinking&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Writing is a powerful teaching tool! It&amp;rsquo;s the most scalable and flexible way to teach dozens, hundreds or even thousands of people about something. That&amp;rsquo;s because text is a universal format. Diagrams or visuals are harder to produce and maintain. Conference talks, videos or podcasts are even harder to produce and maintain over time (they&amp;rsquo;re essentially immutable artifacts)&lt;/li&gt;
&lt;li&gt;Text is easy to edit and collaborate on. It&amp;rsquo;s much harder to do this with other medium.&lt;/li&gt;
&lt;li&gt;Technical writing is an incredible tool to add value to your team. Onboarding documentation unlocks efficient onboarding, incident runbooks lead to fast mitigations.&lt;/li&gt;
&lt;li&gt;Text can be easily distributed and has no fidelity loss when shared (compared to talking to Alice about what Bob told you Charlie said in a meeting that none of you were at).&lt;/li&gt;
&lt;li&gt;Writing creates a record, as opposed to &amp;ldquo;wait, why did we decide on X?&amp;rdquo;&lt;/li&gt;
&lt;li&gt;Writing is applicable almost anywhere when you work as a software engineer: PR descriptions and comments, issue tracker, technical specifications, &amp;ldquo;one-pager&amp;rdquo; documents, meeting agendas and notes, Slack, public forums, incident management, communication with management, knowledge sharing in the form of slides or documents, promo packets, peer feedback, long-form documentation, code comments. Given the range of applicability it&amp;rsquo;s a no-brainer to try to improve as a writer. &lt;strong&gt;Small gains in writing efficiency, clarity, speed, or impact will yield massive benefits for your career&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;resources-to-improve&#34;&gt;Resources to improve&lt;/h1&gt;
&lt;p&gt;Ready to improve? Good! Here is a list of resources I&amp;rsquo;ve come across over the years. Hope you find it useful!&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;On writing good technical documentation: &lt;a href=&#34;https://documentation.divio.com/introduction/&#34;&gt;https://documentation.divio.com/introduction/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Tighten up your prose, write clearly: &lt;a href=&#34;https://www.goodreads.com/book/show/53343.On_Writing_Well&#34;&gt;https://www.goodreads.com/book/show/53343.On_Writing_Well&lt;/a&gt;, &lt;a href=&#34;http://www.plainenglish.co.uk/how-to-write-in-plain-english.html&#34;&gt;http://www.plainenglish.co.uk/how-to-write-in-plain-english.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Become better at documentation and technical design docs: &lt;a href=&#34;https://developers.google.com/tech-writing&#34;&gt;https://developers.google.com/tech-writing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Become better at asking/answering questions on Slack: &lt;a href=&#34;https://nedbatchelder.com//blog/202009/how_to_be_helpful_online.html&#34;&gt;https://nedbatchelder.com//blog/202009/how_to_be_helpful_online.html&lt;/a&gt;, &lt;a href=&#34;https://dontasktoask.com/&#34;&gt;https://dontasktoask.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;To become better at writing, start writing more! &lt;a href=&#34;https://bookpub.club/post/to-write-better-you-need-to-develop-a-habit-of-writing&#34;&gt;https://bookpub.club/post/to-write-better-you-need-to-develop-a-habit-of-writing&lt;/a&gt;–1603298302647x354487348376371200&lt;/li&gt;
&lt;li&gt;Lazy (especially when wide!) communication is costly: &lt;a href=&#34;https://blog.mitchjlee.com/2020/your-writing-style-is-costly&#34;&gt;https://blog.mitchjlee.com/2020/your-writing-style-is-costly&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;On asking and answering questions (applies to Slack specifically – and PR reviews to some extent): &lt;a href=&#34;https://jvns.ca/blog/answer-questions-well/&#34;&gt;https://jvns.ca/blog/answer-questions-well/&lt;/a&gt;, &lt;a href=&#34;https://jvns.ca/blog/good-questions/&#34;&gt;https://jvns.ca/blog/good-questions/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Writing is thinking: &lt;a href=&#34;https://alistapart.com/article/writing-is-thinking/&#34;&gt;https://alistapart.com/article/writing-is-thinking/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;On Writing &amp;ldquo;simple explanations&amp;rdquo; without sounding condescending: &lt;a href=&#34;https://jvns.ca/blog/2020/11/15/simple-explanations-without-sounding-condescending/&#34;&gt;https://jvns.ca/blog/2020/11/15/simple-explanations-without-sounding-condescending/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Comprehensive guide, covering a lot of aspects of writing: &lt;a href=&#34;https://www.julian.com/guide/write/&#34;&gt;https://www.julian.com/guide/write/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Mixed bag of advice from Kurt Vonnegut, one of my favorite authors: &lt;a href=&#34;https://lithub.com/kurt-vonneguts-greatest-writing-advice/&#34;&gt;https://lithub.com/kurt-vonneguts-greatest-writing-advice/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;The Art of Storytelling, by Pixar! This is useful when you want to put together a presentation: &lt;a href=&#34;https://www.khanacademy.org/computing/pixar/storytelling&#34;&gt;https://www.khanacademy.org/computing/pixar/storytelling&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;The Science of Scientific writing: &lt;a href=&#34;http://www.inf.fu-berlin.de/lehre/pmo/eng/ScientificWriting.pdf&#34;&gt;http://www.inf.fu-berlin.de/lehre/pmo/eng/ScientificWriting.pdf&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Write in Plain English: &lt;a href=&#34;https://www.plainenglish.co.uk/how-to-write-in-plain-english.html&#34;&gt;https://www.plainenglish.co.uk/how-to-write-in-plain-english.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;PG on &amp;ldquo;Writing, briefly&amp;rdquo;: &lt;a href=&#34;http://www.paulgraham.com/writing44.html&#34;&gt;http://www.paulgraham.com/writing44.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;The day you became a better writer: &lt;a href=&#34;https://dilbertblog.typepad.com/the_dilbert_blog/2007/06/the_day_you_bec.html&#34;&gt;https://dilbertblog.typepad.com/the_dilbert_blog/2007/06/the_day_you_bec.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Make your point and get out of the way: &lt;a href=&#34;https://www.collaborativefund.com/blog/make-your-point-and-get-out-of-the-way/&#34;&gt;https://www.collaborativefund.com/blog/make-your-point-and-get-out-of-the-way/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;How to write usefully: &lt;a href=&#34;http://paulgraham.com/useful.html&#34;&gt;http://paulgraham.com/useful.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Writing as a superpower: &lt;a href=&#34;https://ckarchive.com/b/p9ueh9hge88w&#34;&gt;https://ckarchive.com/b/p9ueh9hge88w&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;50 quick hits/tips: &lt;a href=&#34;https://www.poynter.org/reporting-editing/2006/fifty-writing-tools-quick-list/&#34;&gt;https://www.poynter.org/reporting-editing/2006/fifty-writing-tools-quick-list/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;13 tips to make any piece of writing better: &lt;a href=&#34;https://medium.com/an-idea-for-you/13-ways-to-turn-the-next-thing-you-write-into-the-best-thing-youve-written-322005cfddc0&#34;&gt;https://medium.com/an-idea-for-you/13-ways-to-turn-the-next-thing-you-write-into-the-best-thing-youve-written-322005cfddc0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;venturehack&amp;rsquo;s take on business writing: &lt;a href=&#34;https://venturehacks.com/writing&#34;&gt;https://venturehacks.com/writing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;40 one sentence writing tips: &lt;a href=&#34;https://joshspector.com/one-sentence-writing-tips/&#34;&gt;https://joshspector.com/one-sentence-writing-tips/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;9 qualities of good writing: &lt;a href=&#34;https://annhandley.com/9-qualities-of-good-writing&#34;&gt;https://annhandley.com/9-qualities-of-good-writing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Designer as writer: &lt;a href=&#34;https://stasaki.com/designer-as-writer/&#34;&gt;https://stasaki.com/designer-as-writer/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Writing Tools Learned from The Economist: &lt;a href=&#34;https://builtbywords.substack.com/p/writing-tools-i-learned-from-the&#34;&gt;https://builtbywords.substack.com/p/writing-tools-i-learned-from-the&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Patterns in confusing explanations: &lt;a href=&#34;https://jvns.ca/blog/confusing-explanations&#34;&gt;https://jvns.ca/blog/confusing-explanations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Advice how to structure math explanations (a lot of it relevant to technical writing): &lt;a href=&#34;https://youtu.be/ojjzXyQCzso?t=500&#34;&gt;https://youtu.be/ojjzXyQCzso?t=500&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;What I&amp;rsquo;ve learnt so far about writing research papers: &lt;a href=&#34;https://tratt.net/laurie/blog/entries/what_ive_learnt_so_far_about_writing_research_papers.html&#34;&gt;https://tratt.net/laurie/blog/entries/what_ive_learnt_so_far_about_writing_research_papers.html&lt;/a&gt;. The conclusion resonates a lot.&lt;/li&gt;
&lt;li&gt;Writing non-advice: &lt;a href=&#34;https://danluu.com/writing-non-advice/&#34;&gt;https://danluu.com/writing-non-advice/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;You should write blogs: &lt;a href=&#34;https://sites.google.com/site/steveyegge2/you-should-write-blogs&#34;&gt;https://sites.google.com/site/steveyegge2/you-should-write-blogs&lt;/a&gt;. Steve Yegge makes good case for writing more in general. Replace &amp;ldquo;blogs&amp;rdquo; with &amp;ldquo;wiki pages&amp;rdquo; or &amp;ldquo;docs&amp;rdquo; in your mind!&lt;/li&gt;
&lt;li&gt;Writing Cultures Win: &lt;a href=&#34;https://founder-fodder.ghost.io/writing-cultures-win/&#34;&gt;https://founder-fodder.ghost.io/writing-cultures-win/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;How to Write More Clearly, Think More Clearly, and Learn Complex Material More Easily (slides): &lt;a href=&#34;http://www.covingtoninnovations.com/mc/WriteThinkLearn.pdf&#34;&gt;http://www.covingtoninnovations.com/mc/WriteThinkLearn.pdf&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Writing for engineers (some really good tips in there!): &lt;a href=&#34;https://www.heinrichhartmann.com/posts/writing&#34;&gt;https://www.heinrichhartmann.com/posts/writing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;How to write docs loved by other developers: &lt;a href=&#34;https://thenewstack.io/an-engineers-best-tips-for-writing-documentation-devs-love&#34;&gt;https://thenewstack.io/an-engineers-best-tips-for-writing-documentation-devs-love&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Writing better docs (1-pagers, design docs, postmortems): &lt;a href=&#34;https://eugeneyan.com/writing/writing-docs-why-what-how/&#34;&gt;https://eugeneyan.com/writing/writing-docs-why-what-how/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Don&amp;rsquo;t think to write, write to think: &lt;a href=&#34;https://herbertlui.net/dont-think-to-write-write-to-think/&#34;&gt;https://herbertlui.net/dont-think-to-write-write-to-think/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Handbook for Writers: &lt;a href=&#34;https://saylordotorg.github.io/text_handbook-for-writers/index.html&#34;&gt;https://saylordotorg.github.io/text_handbook-for-writers/index.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Why Write: &lt;a href=&#34;https://bastian.rieck.me/blog/posts/2023/writing_why/&#34;&gt;https://bastian.rieck.me/blog/posts/2023/writing_why/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Why Engineers Should Focus on Writing: &lt;a href=&#34;https://www.yieldcode.blog/post/why-engineers-should-write/&#34;&gt;https://www.yieldcode.blog/post/why-engineers-should-write/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Write About What You Learn: &lt;a href=&#34;https://addyosmani.com/blog/write-learn/&#34;&gt;https://addyosmani.com/blog/write-learn/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Software Technical Writing, A Guidebook: &lt;a href=&#34;https://jamesg.blog/book.pdf&#34;&gt;https://jamesg.blog/book.pdf&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;How to Write Blog Posts that Developers Read: &lt;a href=&#34;https://refactoringenglish.com/chapters/write-blog-posts-developers-read/&#34;&gt;https://refactoringenglish.com/chapters/write-blog-posts-developers-read/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;The Golden Rule for Becoming a Better Writer: &lt;a href=&#34;https://nappertime.com/the-golden-rule-of-becoming-a-better-writer&#34;&gt;https://nappertime.com/the-golden-rule-of-becoming-a-better-writer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;How To Write With An LLM: &lt;a href=&#34;https://sockpuppet.org/blog/2026/09/17/how-to-write-with-an-llm&#34;&gt;https://sockpuppet.org/blog/2026/09/17/how-to-write-with-an-llm&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Anti-Patterns in Software Blogging: &lt;a href=&#34;https://refactoringenglish.com/blog/anti-patterns-software-blogging&#34;&gt;https://refactoringenglish.com/blog/anti-patterns-software-blogging&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Techniques for Improving Your Technical Writing: &lt;a href=&#34;https://blog.colinbreck.com/techniques-for-improving-your-technical-writing/&#34;&gt;https://blog.colinbreck.com/techniques-for-improving-your-technical-writing/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;I Don&amp;rsquo;t Want to Read What You Didn&amp;rsquo;t Write: &lt;a href=&#34;https://blog.colinbreck.com/i-dont-want-to-read-what-you-didnt-write&#34;&gt;https://blog.colinbreck.com/i-dont-want-to-read-what-you-didnt-write&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now, here are some resources which I have not read/vetted yet, but I&amp;rsquo;ve seen recommended by people I trust:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Clear and Simple as Truth, writing classic prose: &lt;a href=&#34;https://www.amazon.com/gp/product/0691147434&#34;&gt;https://www.amazon.com/gp/product/0691147434&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Skunk &amp;amp; White&amp;rsquo;s &amp;ldquo;The Elements of Style&amp;rdquo; (a classic!): &lt;a href=&#34;https://www.amazon.com/gp/product/020530902X&#34;&gt;https://www.amazon.com/gp/product/020530902X&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Analyzing Prose: &lt;a href=&#34;https://www.amazon.com/gp/product/0826461905&#34;&gt;https://www.amazon.com/gp/product/0826461905&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Prose, the art of non-fiction: &lt;a href=&#34;https://www.amazon.com/gp/product/0812982150/&#34;&gt;https://www.amazon.com/gp/product/0812982150/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Donald Knuth blurring the line between technical writing and coding with the concept of Literate Programing (&lt;a href=&#34;https://www.amazon.com/Literate-Programming-Lecture-Notes-Donald/dp/0937073806/&#34;&gt;Amazon link&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;notes-from-what-ive-read-so-you-dont-have-to&#34;&gt;Notes from what I&amp;rsquo;ve read (so you don&amp;rsquo;t have to)&lt;/h1&gt;
&lt;p&gt;This section contains notes from articles or books which particularly resonated with me. Expand to read through them.&lt;/p&gt;
&lt;h2 id=&#34;write-better-right-now-mary-kate-mackey&#34;&gt;Write Better Right now (Mary-Kate Mackey)&lt;/h2&gt;
&lt;details&gt;&lt;summary&gt;Notes about &#34;Write Better Right now&#34; (Mary-Kate Mackey)&lt;/summary&gt;
&lt;p&gt;Below, some notes from reading &amp;ldquo;Write Better Right now&amp;rdquo; (&lt;a href=&#34;https://www.amazon.com/Write-Better-Right-Now-Communication/dp/1632650630&#34;&gt;Amazon link&lt;/a&gt;)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;this book is for reluctant writers. I&amp;rsquo;d put most engineers in this category. Writing is something we have to do. Not something we typically enjoy doing&lt;/li&gt;
&lt;li&gt;it&amp;rsquo;s really odd to me that software engineers love refactoring code but don&amp;rsquo;t pay as much attention to text. The parallel is obvious: code is information for computers, prose is information for humans. The puzzles encountered when refactoring code are similar to the ones of document editing.&lt;/li&gt;
&lt;li&gt;writing isn&amp;rsquo;t hard. It&amp;rsquo;s the thinking that&amp;rsquo;s hard. Writing is a practice to clarify one&amp;rsquo;s thinking. Yet it&amp;rsquo;s often seen as something &amp;ldquo;extra&amp;rdquo;. For example: design docs. The primary goal is to clarify the design. A secondary goal is to make the design shareable and agreed upon. A nice side-effect: you now have a long-lasting artifact to point to and reflect on when comes perf/promo cycle.&lt;/li&gt;
&lt;li&gt;Types of writers: planners, plungers, matchers. I&amp;rsquo;m a plunger for sure.&lt;/li&gt;
&lt;li&gt;Focus for writing: solve your reader&amp;rsquo;s problem. It starts by defining the problem, and the reader. &amp;ldquo;What&amp;rsquo;s in it for me?&amp;rdquo;&lt;/li&gt;
&lt;li&gt;Copy more! As engineers we deconstruct and copy code all the time. Why not do the same with English? Imitate Slack announcement that you like, copy the doc styles that you find effective. Don&amp;rsquo;t be shy.&lt;/li&gt;
&lt;li&gt;As engineers we review code and have a healthy stance: &amp;ldquo;you are not your code&amp;rdquo;. I&amp;rsquo;d like to pilot technical writing review which discusses grammar, writing flaws, etc. It&amp;rsquo;d be really valuable.\&lt;/li&gt;
&lt;li&gt;Word count technique: for every paragraph, write down a condensed count per sentence. Then spot patterns across your document. You may need to vary sentence lengths based on this, to keep the rhythm un-boring. This paragraph is 13-6-16-4-9. Replicate somebody else&amp;rsquo;s word count to borrow their rhythm&lt;/li&gt;
&lt;li&gt;When writing something, have a north star (&amp;ldquo;cable car sentence&amp;rdquo; in the book). Fill the blanks: &amp;ldquo;In my &lt;code&gt;_____&lt;/code&gt; (writing category) about &lt;code&gt;_______&lt;/code&gt; (subject) I am saying that &lt;code&gt;______&lt;/code&gt; (slant)&amp;rdquo;. To find the slant of a piece of writing, ask the following questions: what&amp;rsquo;s this piece of writing about? Why is it being told? How does it connect to the greater world? What&amp;rsquo;s the point? In one word, what&amp;rsquo;s this about?&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Shoeboxing&amp;rdquo; is another technique to spot the theme of a piece: the idea is to label each paragraph with a short label, as if you were to put it in a shoebox and put it in storage.&lt;/li&gt;
&lt;li&gt;Edits come in 3 forms:
&lt;ul&gt;
&lt;li&gt;&amp;ldquo;big picture&amp;rdquo; edit where you check the structure and whether your writing does its job well. Check against the cable-car sentence / slant. Be mindful of multiple interleaved ideas. Simplify.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;medium&amp;rdquo; edits are about strengthening verbs (avoid to be/have verbs, minimize adverbs, check for tenses); shoeboxing paragraphs to check their lengths and make sure they follow a logical progression; be on the lookout for too many pronouns. Pay special attention to the first and last sentence of your paragraphs. They&amp;rsquo;re the &amp;ldquo;signpost&amp;rdquo; sentence and the &amp;ldquo;springboards&amp;rdquo; that guide readers through your writing. Pay attention to transitions to make sure readers are brought along (transitions can be by opposites, time, place, jump cuts, quotes, questions, facts, point of view, onee liners, observations, compactions summation).&lt;/li&gt;
&lt;li&gt;&amp;ldquo;close up&amp;rdquo; edits are the typical typos, spell checking, punctuation, grammar. This is where you take a styleguide and apply it consistently. That&amp;rsquo;s the most natural kind of &amp;ldquo;edit&amp;rdquo; for us engineers. The parallel in code would be checking for extra whitespace, missing dangling commas, indentation problems. Makes your code looks neater, but medium and big picture feedback is far more valuable IMO. We don&amp;rsquo;t do enough of those.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;h2 id=&#34;the-science-of-scientific-writing-george-d-gopen-and-judith-a-swan&#34;&gt;The Science of Scientific Writing (George D. Gopen and Judith A. Swan)&lt;/h2&gt;
&lt;details&gt;&lt;summary&gt;Notes about &#34;The Science of Scientific Writing&#34; (George D. Gopen and Judith A. Swan)&lt;/summary&gt;
&lt;p&gt;From &lt;a href=&#34;http://www.inf.fu-berlin.de/lehre/pmo/eng/ScientificWriting.pdf&#34;&gt;The Science of Scientific Writing (George D. Gopen and Judith A. Swan)&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Follow a grammatical subject as soon as possible with its verb&lt;/li&gt;
&lt;li&gt;Place in the stress position the “new information” you want the reader to emphasize.&lt;/li&gt;
&lt;li&gt;Place the person or thing whose “story” a sentence is telling at the beginning of the sentence, in the topic position.&lt;/li&gt;
&lt;li&gt;Place  appropriate  “old  information”  (material  already  stated  in  the  discourse)  in  the  topic  position  for  linkage backward and contextualization forward.&lt;/li&gt;
&lt;li&gt;Articulate the action of every clause or sentence in its verb.&lt;/li&gt;
&lt;li&gt;In general, provide context for your reader before asking that reader to consider anything new.&lt;/li&gt;
&lt;li&gt;In general, try to ensure that the relative emphases of the substance coincide with the relative expectations for emphasis raised by the structure.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Another gem from this short paper: &amp;ldquo;Our best stylists turn out to be our most skillful violators; but in order to carry this off, they must fulfill expectations most of the time, causing the violations to be perceived as exceptional moments, worthy of note&amp;rdquo;. And finally: &amp;ldquo;The writing principles we have suggested here make conscious for the writer some of the interpretive clues readers derive from structures. Armed with this awareness, the writer can achieve far greater control (although never complete control) of the reader’s interpretive process. As a concomitant function, the principles simultaneously offer the writer a fresh re-entry to the thought process that produced the science. In real and important ways, the structure of the prose becomes the structure of the scientific argument. Improving either one will improve the other.&amp;rdquo;&lt;/p&gt;
&lt;/details&gt;
&lt;h2 id=&#34;patterns-in-confusing-explanations-julia-evans&#34;&gt;Patterns in confusing explanations (Julia Evans)&lt;/h2&gt;
&lt;details&gt;&lt;summary&gt;Notes about &#34;Patterns in confusing explanations&#34; (Julia Evans)&lt;/summary&gt;
&lt;p&gt;Julia Evans strikes once again. She wrote this wonderful summary of patterns in confusing explanations and gave some tips to avoid them. Here are the takeaways from my point of view (full article is &lt;a href=&#34;https://jvns.ca/blog/confusing-explanations&#34;&gt;here&lt;/a&gt;):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Have an expert (or somebody who&amp;rsquo;s familiar with the concept) review your explanation. This avoids key concepts being missed.&lt;/li&gt;
&lt;li&gt;Review the assumptions you&amp;rsquo;re making about your readers; who are you writing for? Where are they starting in terms of understanding?&lt;/li&gt;
&lt;li&gt;Test your explanation on somebody who has never been exposed to the concept before. This validates the assumptions you&amp;rsquo;re making about your readers.&lt;/li&gt;
&lt;li&gt;Avoid long-running analogies. Prefer short-lived ones to illustrate a point&lt;/li&gt;
&lt;li&gt;Don&amp;rsquo;t insert pictures to make an explanation &amp;ldquo;cute&amp;rdquo;; only insert them if they enhance a point you&amp;rsquo;re trying to make&lt;/li&gt;
&lt;li&gt;Use realistic, working code examples. Not phony ones. And: please please use examples! Examples are crucial for readers to internalize explanations.&lt;/li&gt;
&lt;li&gt;Avoid jargon where it&amp;rsquo;s not needed; use simple words instead&lt;/li&gt;
&lt;li&gt;Start concrete, then abstract. Not the opposite (interestingly, 3blue1brown makes a similar case in &lt;a href=&#34;https://youtu.be/ojjzXyQCzso?t=500&#34;&gt;his advice on how to structure math explanations&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Explanations should read like proofs: don&amp;rsquo;t add in information without supporting evidence! In other words, don&amp;rsquo;t be sloppy. Add links to reference docs, prove your point with a working code snippet, link to actual production code, etc.&lt;/li&gt;
&lt;li&gt;If you present pitfalls/mistakes, clearly label them as such. If possible in a separate document. Otherwise readers do not know what&amp;rsquo;s right and what wrong.&lt;/li&gt;
&lt;li&gt;Explain why. Even if it&amp;rsquo;s a reduced, not-so-universal, or even personal &amp;ldquo;why&amp;rdquo;. Be honest with why you&amp;rsquo;re explaining something or using a technology, that will help your readers get in the same frame of mind.&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
</description>
    </item>
    <item>
      <title>Bypassing geo-restrictions with ssh</title>
      <link>https://arnaudbrousseau.com/notes/bypassing-geo-restrictions-with-ssh.html</link>
      <pubDate>Sun, 26 Sep 2021 10:47:03 -0500</pubDate>
      <guid>https://arnaudbrousseau.com/notes/bypassing-geo-restrictions-with-ssh.html</guid>
      <description>&lt;p&gt;&lt;a href=&#34;http://manpages.org/ssh&#34;&gt;&lt;code&gt;ssh&lt;/code&gt;&lt;/a&gt; is an amazing Unix tool. One of its many
powers: bypassing geo-restrictions by acting as a forward proxy.&lt;/p&gt;
&lt;h1 id=&#34;setting-up-a-forward-proxy-with-ssh&#34;&gt;Setting up a forward proxy with ssh&lt;/h1&gt;
&lt;p&gt;You will need access to a remote server to do this. I already have a
few servers I rent in different regions to host a variety of websites; the
ability to use these as proxies is pure bonus!&lt;/p&gt;
&lt;p&gt;Without further ado here&amp;rsquo;s the single &lt;code&gt;ssh&lt;/code&gt; command you need to create a proxy:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ ssh -D 8123 -f -C -q -N user@host
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Let&amp;rsquo;s break down the &lt;code&gt;ssh&lt;/code&gt; options (extracted from the man page):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-D&lt;/code&gt;: Specifies a local dynamic application-level port
forwarding. This works by allocating a socket to listen to
port on the local side. Whenever a connection is made to this
port, the connection is forwarded over the secure channel,
and the application protocol is then used to determine where
to connect to from the remote machine. ssh will act as a SOCKS server.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-f&lt;/code&gt;: Requests ssh to go to background just before command execution. This is
useful if ssh is going to ask for passwords or passphrases, but the user
wants it in the background&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-N&lt;/code&gt;: Do not execute a remote command. This is useful for just forwarding ports&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-C&lt;/code&gt;: Requests compression of all data. The compression algorithm is the same used by gzip&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-q&lt;/code&gt;: Quiet mode. Causes most warning and diagnostic messages to be suppressed&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In practice I have two aliases to toggle proxying on and off easily:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;alias proxyon=&#39;ssh -D 8123 -f -C -q -N user@host&#39;
alias proxyoff=&#39;killall -v ssh&#39;
&lt;/code&gt;&lt;/pre&gt;&lt;h1 id=&#34;browsing-with-a-proxy&#34;&gt;Browsing with a proxy&lt;/h1&gt;
&lt;p&gt;Once you have a local port set up to forward traffic onto a remote host,
browsing the web using it is simple.&lt;/p&gt;
&lt;p&gt;In Firefox, go to Preferences &amp;gt; Network Settings &amp;gt; Settings &amp;gt; Manual Proxy
Configuration. Then fill in &amp;ldquo;localhost&amp;rdquo; and &amp;ldquo;8123&amp;rdquo;. Click OK and you&amp;rsquo;re good to
go!&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/firefox-proxy-settings.png&#34; alt=&#34;Firefox Preferences&#34;&gt;&lt;/p&gt;
&lt;p&gt;Chrome (on MacOSX) relies on system-wide proxy settings: System
Preferences &amp;gt; Network &amp;gt; Advanced &amp;gt; Proxies. Tick &amp;ldquo;SOCKS Proxy&amp;rdquo; and fill in
&amp;ldquo;localhost&amp;rdquo; and &amp;ldquo;8123&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/system-proxy-settings.png&#34; alt=&#34;System Preferences&#34;&gt;&lt;/p&gt;
&lt;p&gt;&amp;hellip;that&amp;rsquo;s all there is to it! Goodbye geo-restrictions.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Push Terror</title>
      <link>https://arnaudbrousseau.com/notes/push-terror.html</link>
      <pubDate>Tue, 31 Aug 2021 00:29:06 -0500</pubDate>
      <guid>https://arnaudbrousseau.com/notes/push-terror.html</guid>
      <description>&lt;p&gt;I first experienced &amp;ldquo;Push Terror&amp;rdquo; in 2012. At the time I was starting my career
as an engineer, at Yelp.
Yelp was (probably still is) powered by a gigantic Python monolith called
&amp;ldquo;yelp-main&amp;rdquo;. To support releasing new yelp-main versions a set of
engineers known as &amp;ldquo;pushmasters&amp;rdquo; were dedicated to the task of gathering dev
branches, merge them into a release branch, and shepherd it to production,
multiple times a day.&lt;/p&gt;
&lt;p&gt;Push Terror describes what happens right after the final &amp;ldquo;Return&amp;rdquo; key is pressed;
right after a new yelp-main deployment is launched. Off we go, folks! Now what?
Push Terror. Pushmasters and pushees wait, anxiously. They prepare,
meticulously. The release hits production, slowly. 1%, 2%, 5%, 10%&amp;hellip;sweating yet?
Time to prep rollback commands, pull up dashboards, tail error logs, have one more
look at prod configs, just in case.&lt;/p&gt;
&lt;p&gt;Experienced pushmasters would learn to vet individual changes, build a rough
mental map of what could go wrong, and ask pointed questions to new pushees.
Will this be safe to rollback? Did you remember to translate this? What about
your testing plan here?&lt;/p&gt;
&lt;p&gt;Experienced pushees would figure out, over time, which pushmaster to lean on
when a risky change had to be deployed. Risky changes go out in the morning
push to minimize blast radius. Safe ones during main business hours. Maybe we
need a custom deployment for this because it&amp;rsquo;s more risky than usual.&lt;/p&gt;
&lt;p&gt;In the years I spent at Yelp I&amp;rsquo;ve dealt with Push Terror both as a pushmaster
and a pushee. It has taught me a few important, hard-to-teach skills. Let&amp;rsquo;s
cover a couple of them.&lt;/p&gt;
&lt;p&gt;The first one is preparation. As in: preparing my code and thinking through how
it&amp;rsquo;s going to make it to production. How do I minimize Push Terror? Logging,
good error handling, feature toggles, a plan when database structure needs to
change, and some tickets to configure the different environments are a good
start. Oh and: a testing plan! You do not want to be figuring out which
commands to run or where to click while Push Terror is lowering your IQ by a
couple dozen points.&lt;/p&gt;
&lt;p&gt;Second: embrace risk. I&amp;rsquo;ve seen a &lt;em&gt;comment update&lt;/em&gt; cause a site-wide
outage when deployed to production. &amp;ldquo;How on Earth&amp;rdquo;, you ask? Unicode + Python 2
≠ Good Times. But that&amp;rsquo;s besides the point. The point is: some amount of Push
Terror is healthy. You can&amp;rsquo;t aim to feel 100% confident before deploying code.
You&amp;rsquo;ll probably never get there because there&amp;rsquo;s &lt;em&gt;always&lt;/em&gt; a chance something
will go wrong. Deployments should feel risky, because they are. Embrace this
feeling and execute on what you&amp;rsquo;ve prepared: pull up logs, dashboards, and
pre-written plans. Click around in the production app once your new code is
live. &amp;ldquo;Do we still have a website/app?&amp;rdquo; should be a question on your mind.
Don&amp;rsquo;t take this for granted! Did anything regress? Is your feature looking good?
Is your bug actually fixed? Did anything slow down? Did error rates spike up?
And what else?&lt;/p&gt;
&lt;p&gt;Push Terror has served me well. It&amp;rsquo;s shaped my instincts about preparation and
risks over time. I hope reading this will instill a healthy dose of Push Terror
during your next production deployment. Godspeed!&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Apprenticeship Patterns</title>
      <link>https://arnaudbrousseau.com/notes/apprenticeship-pattern.html</link>
      <pubDate>Sun, 04 Apr 2021 13:30:38 -0700</pubDate>
      <guid>https://arnaudbrousseau.com/notes/apprenticeship-pattern.html</guid>
      <description>&lt;p&gt;I picked up &lt;a href=&#34;https://www.amazon.com/_/dp/0596518382&#34;&gt;Apprenticeship Patterns&lt;/a&gt;
and finished reading it recently. It was written in 2009. 10+ years later I
still found it relevant, energizing, and insightful. Let&amp;rsquo;s go through why.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/apprenticeship-patterns-cover.jpg&#34; alt=&#34;Apprenticeship Patterns&#34;&gt;&lt;/p&gt;
&lt;h1 id=&#34;apprenticeship-patterns-the-good-parts&#34;&gt;Apprenticeship Patterns: The Good Parts&lt;/h1&gt;
&lt;p&gt;Our industry&amp;rsquo;s practices have evolved. While some advice or reflections in this
book are dusty, it offers timeless high-quality &amp;ldquo;patterns&amp;rdquo; (really, mindsets)
that one can leverage in today&amp;rsquo;s world. Here are some that resonated with me
particularly well:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Expose Your Ignorance, Confront Your Ignorance&lt;/strong&gt;: don&amp;rsquo;t hide your ignorance,
and actively seek to discover your own gaps.  Ask questions publicly when
possible. Confronting one&amp;rsquo;s ignorance is about spending deliberate energy to
dig deeper and plug the holes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Study The Classics, Use The Source, Dig Deeper&lt;/strong&gt;: this is about studying
&amp;ldquo;canonical&amp;rdquo; sources of knowledge rather than derived or second-hand accounts.
Go read The Mythical Man-Month and judge for yourself. Use &amp;ldquo;view source&amp;rdquo; on
websites that you&amp;rsquo;re impressed by. Clone the libraries you use and pry them
open. Follow your curiosity as deep as you can.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Breakable Toys&lt;/strong&gt;: this mindset is a solution to confront a gap in
understanding. If you do not understand something deeply enough, make a
small, throwaway, breakable &amp;ldquo;toy&amp;rdquo;. What matters is that you&amp;rsquo;re allowed to
fail and goof around, like a kid.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Be The Worst&lt;/strong&gt;: relevant 20 years ago, and still relevant today. You are an
average of the people who surround you. Hence, if you&amp;rsquo;re the worst when you
look around, you&amp;rsquo;re in a great place. Keep pushing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Stay In The Trenches&lt;/strong&gt;: an ode to committment to the IC track. Do not go into
management if you&amp;rsquo;re planning to hone your software skills. It takes a lot of
willpower to remain close to the code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Kindred Spirits, Rubbing Elbows&lt;/strong&gt;: early in my career I&amp;rsquo;ve benefitted immensely
from senior developers taking me &amp;ldquo;under their wings&amp;rdquo;
(&lt;a href=&#34;https://twitter.com/jrheard&#34;&gt;@jrheard&lt;/a&gt;,
&lt;a href=&#34;https://pypi.org/user/buck/&#34;&gt;Buck&lt;/a&gt;). Don&amp;rsquo;t underestimate the importance of
mentorship and social interactions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Learn How you Fail&lt;/strong&gt;: this is something I used to prepare for coding interviews.
As you write a program, write down every mistake you make. Then reflect on
how you fail as patterns emerge: off-by-one errors? Undeclared variables?
Syntax problems? What are your most common failure modes?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Nurture Your Passion&lt;/strong&gt;: passion is not something that exists before you get
into a craft. Same with software. So, to stay passionate, you have to nurture
your passion deliberately. Unfortunately it may involve work outside of your
normal day job if your current job isn&amp;rsquo;t enough to nurture your passion.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Record What You Learn&lt;/strong&gt;: probably the most important mindset of all in my
opinion. Writing or recording what you learn is a huge force-multiplier for a
software engineering career. Do this during your day job if possible; outside if not.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;mapping-my-usual-advice-to-patterns&#34;&gt;Mapping my usual advice to patterns&lt;/h1&gt;
&lt;p&gt;I often take explicit or implicit mentorship responsibilities at work. Reading
through this book I realized the advice I give fits into apprenticeship patterns:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;&amp;ldquo;Write things down!&amp;quot;&lt;/em&gt;: I give this advice in the context of promotions (where
artifacts matter a lot!). Fits squarely inside of Record What You Learn.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&amp;ldquo;Ship some code first&amp;rdquo;&lt;/em&gt;: I often tell senior engineers (or even engineering
managers) who start on the job that the most important thing they can do is
get a feeling for what it&amp;rsquo;s like to ship code, or acquire deep technical
expertise about &amp;ldquo;the reality on the ground&amp;rdquo;. This is a version of Stay In The
Trenches (&amp;ldquo;Jump In The Trenches&amp;rdquo;?)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&amp;ldquo;Learn how to use a debugger, and get good at debugging!&amp;quot;&lt;/em&gt;: I&amp;rsquo;m triggered when
I see folks use print-based debugging to diagnose issues in their code. So I
introduce everyone who works with me to the importance of debuggers.
Generally speaking, debugging is a crucial skill in software engineering.
When you write code, when you test code, or when you&amp;rsquo;re handling production
incidents. This advice doesn&amp;rsquo;t really have a pattern directly mapping to it,
although it&amp;rsquo;s closest to Confront Your Ignorance&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&amp;ldquo;Reduce to the simplest possible case&amp;rdquo;&lt;/em&gt;: I&amp;rsquo;m always in favor of reducing a
problem to its minimal parts. Usually it&amp;rsquo;s in the context of a bug. I&amp;rsquo;m a big
fan of &amp;ldquo;minimal repros&amp;rdquo; and proof-of-concept implementations (&amp;ldquo;POCs&amp;rdquo;). This
is squarely within the Breakable Toys pattern&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&amp;ldquo;Find good mentors, expand your social network, and do more pair
programming&amp;rdquo;&lt;/em&gt;: is also a recurring advice I give to anyone who&amp;rsquo;s looking to
get better at writing software. I realize it is just another way of applying
Kindred Spirits and Rubbing Elbows.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;committing-to-craftsmanship&#34;&gt;Committing to craftsmanship&lt;/h1&gt;
&lt;p&gt;Reading this book has had a good effect on me. It clarified what I&amp;rsquo;m committed
to now, and in the future. Specifically, here&amp;rsquo;s what lies ahead for me:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Resist the temptation to go broad/abstract. Go deep/concrete instead.&lt;/li&gt;
&lt;li&gt;Refuse to go into management. I&amp;rsquo;ve done that successfully so far, aside from
a short stint as an engineering manager for 6 months or so. Luckily I&amp;rsquo;ve
found my way back to engineering. This is a renewed commitment to the
Individual Contributor (&amp;ldquo;IC&amp;rdquo;) track.&lt;/li&gt;
&lt;li&gt;Stay in the trenches. The current IC track at Coinbase is pulling me away
from code in my day job. Time to fight this tendency.&lt;/li&gt;
&lt;li&gt;Read more research papers. Keep reading fundamental books.&lt;/li&gt;
&lt;li&gt;Get involved in open-source work. I haven&amp;rsquo;t found a community I&amp;rsquo;m passionate
about yet but I haven&amp;rsquo;t been looking actively either. I&amp;rsquo;d love to contribute
to Firefox for example.&lt;/li&gt;
&lt;li&gt;Confront my ignorance of Bazel. I don&amp;rsquo;t know how it works right now.&lt;/li&gt;
&lt;li&gt;Confront my ignorance of Golang. I have a surface-level understanding of the language. Too shallow.&lt;/li&gt;
&lt;li&gt;Practice on toy problems on a regular basis. While interview-type problems
are boring, I&amp;rsquo;m hoping that resources like &lt;a href=&#34;https://openlibrary.org/books/OL4546158M/Etudes_for_Programmers&#34;&gt;Etudes for
Programmers&lt;/a&gt;,
&lt;a href=&#34;https://github.com/norvig/pytudes&#34;&gt;Novig&amp;rsquo;s Pytudes&lt;/a&gt;, &lt;a href=&#34;https://projecteuler.net/&#34;&gt;Project
Euler&lt;/a&gt;, or &lt;a href=&#34;https://adventofcode.com&#34;&gt;Advent Of
Code&lt;/a&gt; can provide fun challenges&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;looking-ahead-who-i-aspire-to-become&#34;&gt;Looking Ahead: who I aspire to become&lt;/h1&gt;
&lt;p&gt;Here&amp;rsquo;s a list of people I admire. I realize now that each of them embodies an
aspect of &amp;ldquo;apprenticeship&amp;rdquo; or &amp;ldquo;craftsmanship&amp;rdquo; described in &lt;a href=&#34;https://www.amazon.com/_/dp/0596518382&#34;&gt;Apprenticeship
Patterns&lt;/a&gt;. Here they are, along with
why I find their work so damn impressive:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Julia Evans: master of learning in the open with her &lt;a href=&#34;https://jvns.ca/&#34;&gt;blog&lt;/a&gt;
and &lt;a href=&#34;https://wizardzines.com/&#34;&gt;zines&lt;/a&gt;, on a variety of topics ranging from
DNS to CSS.&lt;/li&gt;
&lt;li&gt;Paul Irish: isn&amp;rsquo;t afraid of digging deep and reading the source. See &lt;a href=&#34;https://www.paulirish.com/2010/10-things-i-learned-from-the-jquery-source/&#34;&gt;10
things I learned from the jQuery source
code&lt;/a&gt;.
Paul&amp;rsquo;s also the reason why Chrome devtools have become so good so quickly.
He&amp;rsquo;s given countless talks about his work and embodies staying in the
trenches. Fighting the corporate monster that Google is today must not be
easy. Hats off!&lt;/li&gt;
&lt;li&gt;Brendan Gregg: king of breakable toys and digging deep. See Brendan&amp;rsquo;s work
&lt;a href=&#34;http://www.brendangregg.com/&#34;&gt;here&lt;/a&gt;; I&amp;rsquo;m a fan of how systematically he&amp;rsquo;s
implemented small tools to fill observability gaps, and how he&amp;rsquo;s combined
them to cover the &lt;a href=&#34;http://www.brendangregg.com/Perf/linux_observability_tools.png&#34;&gt;entirety of
Linux&lt;/a&gt; over
the years&lt;/li&gt;
&lt;li&gt;Ilya Grigorik: a true scholar who&amp;rsquo;s curating the industry standard for web
performance, in the open, at &lt;a href=&#34;https://hpbn.co/&#34;&gt;hpbn.co&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Vitalik Buterin: founder of Ethereum; he&amp;rsquo;s digging deep into research at
&lt;a href=&#34;https://ethresear.ch/&#34;&gt;ethresear.ch&lt;/a&gt; and recording what he learns at
&lt;a href=&#34;https://vitalik.ca/&#34;&gt;vitalik.ca&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    <item>
      <title>Worst Bitcoin Explanation</title>
      <link>https://arnaudbrousseau.com/notes/worst-bitcoin-explanation.html</link>
      <pubDate>Sun, 14 Mar 2021 15:02:00 -0700</pubDate>
      <guid>https://arnaudbrousseau.com/notes/worst-bitcoin-explanation.html</guid>
      <description>&lt;h1 id=&#34;the-explanation&#34;&gt;The Explanation&lt;/h1&gt;
&lt;p&gt;Taken from &lt;a href=&#34;https://www.technologyelevation.com/2021/03/bill-gates-says-that-bitcoin-is-bad-for.html&#34;&gt;this article&lt;/a&gt; (&lt;a href=&#34;https://web.archive.org/web/20210314220648/https://www.technologyelevation.com/2021/03/bill-gates-says-that-bitcoin-is-bad-for.html&#34;&gt;Wayback machine link&lt;/a&gt; in case the live link stops working). Quoting:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Let’s see how Bitcoin cryptocurrency actually works. Bitcoin is an encrypted, public, shared form of money generated by a longer Blockchain code. Blockchain is a set of collective records, also known as Ledger, which stores cryptocurrency transactional records as we do in Excel spreadsheets.&lt;/p&gt;
&lt;p&gt;Bitcoin&amp;rsquo;s model is to store transaction data on volunteer computers for transaction verification. A volunteer computer runs software to verify transactions made under certain rules that involve mutual agreement between both parties, and the buyer has enough money in his Bitcoin wallet.&lt;/p&gt;
&lt;p&gt;The volunteers are known as Miners. Miners are rewarded for their hardware and the energy that computers consume by kickbacks. These kickbacks are in the form of cryptocurrency.&lt;/p&gt;
&lt;p&gt;Bitcoins don’t rely on single computer verification. If the system gets enough verified results from different Miners then the transaction joins the recent transaction of the world as “Block”.&lt;/p&gt;
&lt;p&gt;The math required for the transaction requires so much computing power that it cannot be validated by a single computer or group of users, which prevents the system from generating fake currency.&lt;/p&gt;
&lt;p&gt;Bit mining requires dedicated machines.&lt;/p&gt;
&lt;p&gt;This whole process requires dedicated hardware and consumes a lot of power. In addition, more cooling systems are needed to keep the temperature of the machine low for complicated mathematical processes.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id=&#34;whats-wrong-with-it&#34;&gt;What&amp;rsquo;s wrong with it?&lt;/h1&gt;
&lt;p&gt;This explanation is bad on many levels. It&amp;rsquo;s poorly written and contains many false claims. There&amp;rsquo;s quite a lot to unpack:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&amp;ldquo;Bitcoin is an encrypted, public, shared form of money generated by a longer Blockchain code&amp;rdquo;.&lt;/em&gt;&lt;br&gt;
Bitcoin isn&amp;rsquo;t encrypted. Bitcoin is a public ledger. All transactions are processed in the open. The last part, &amp;ldquo;generated by a longer Blockchain code&amp;rdquo;, just doesn&amp;rsquo;t make any sense. Bitcoin is a currency and a payment network. This network relies on a protocol (specified &lt;a href=&#34;https://en.bitcoin.it/wiki/Protocol_documentation&#34;&gt;here&lt;/a&gt;) and nodes running software implementing this protocol (what the author refers to as &amp;ldquo;longer Blockchain code&amp;rdquo; perhaps?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&amp;ldquo;stores cryptocurrency transactional records as we do in Excel spreadsheets&amp;rdquo;.&lt;/em&gt;&lt;br&gt;
Wow. There is a world of difference between a spreadsheet and Bitcoin. But I&amp;rsquo;m sure you knew this already. Bitcoin&amp;rsquo;s transaction ledger is distributed (each Bitcoin node holds a copy), and based on Unspent Transaction Ouputs (UTXO). The data model is very different from a standard spreadsheet of transactions.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&amp;ldquo;Bitcoin’s model is to store transaction data on volunteer computers for transaction verification&amp;rdquo;.&lt;/em&gt;&lt;br&gt;
Again this is false. A transaction is checked &lt;em&gt;before&lt;/em&gt; it is broadcasted on the network. After a transaction is broadcasted it is not included in a Bitcoin block right away. The transaction typically stays in Bitcoin&amp;rsquo;s &amp;ldquo;mempool &amp;quot; (memory pool) until a miner chooses to include it. See &lt;a href=&#34;https://www.youtube.com/watch?v=kpnTb6NWih0&#34;&gt;this excellent video&lt;/a&gt; for more details on the life cycle of a Bitcoin transaction.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&amp;ldquo;A volunteer computer runs software to verify transactions made under certain
rules that involve mutual agreement between both parties&amp;rdquo;.&lt;/em&gt;&lt;br&gt;
Again, &lt;strong&gt;plain wrong&lt;/strong&gt;. Bitcoin&amp;rsquo;s protocol and consensus rules are established
ahead of time. There is no agreement between parties! In fact, this is one of
the fundamental values of Bitcoin: you can transact with anybody else on the
network without agreeing with them.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&amp;ldquo;The volunteers are known as Miners&amp;rdquo;.&lt;/em&gt;&lt;br&gt;
Partly true, but partly false. Mining is optional in Bitcoin. Full nodes hold a copy of the Bitcoin ledger and validate transactions without mining.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&amp;ldquo;Miners are rewarded for their hardware and the energy that computers consume by kickbacks. These kickbacks are in the form of cryptocurrency&amp;rdquo;.&lt;/em&gt;&lt;br&gt;
This is misleading. Miners are rewarded when they add blocks to the shared ledger. They aren&amp;rsquo;t directly compensated to consume energy. The &amp;ldquo;kickbacks&amp;rdquo; are &lt;a href=&#34;https://learnmeabitcoin.com/technical/coinbase-transaction&#34;&gt;coinbase transactions&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&amp;ldquo;Bitcoins don’t rely on single computer verification. If the system gets enough verified results from different Miners then the transaction joins the recent transaction of the world as &amp;lsquo;Block&amp;rsquo;&amp;rdquo;.&lt;/em&gt;&lt;br&gt;
A Bitcoin block is proposed by the miner who finds it first. There is no verification or threshold of nodes in Bitcoin. The longest chain of valid blocks wins, period.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&amp;ldquo;The math required for the transaction requires so much computing power that it cannot be validated by a single computer or group of users, which prevents the system from generating fake currency&amp;rdquo;.&lt;/em&gt;&lt;br&gt;
Blatantly false. Finding a block is hard. But validating a block is easy! What the author hints at when they mention that it &amp;ldquo;prevents the system from generating fake currency&amp;rdquo; is the double-spend problem. For a good explainer about it, see &lt;a href=&#34;https://en.bitcoinwiki.org/wiki/Double-spending&#34;&gt;this page&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&amp;ldquo;Bit mining requires dedicated machines. This whole process requires dedicated hardware and consumes a lot of power. In addition, more cooling systems are needed to keep the temperature of the machine low for complicated mathematical processes&amp;rdquo;.&lt;/em&gt;&lt;br&gt;
OH. MY. GOD. Finally something the author got right, somewhat! While in theory bitcoin mining is open to everyone and every machine, the reality is that you need dedicated beefy servers with specialized &lt;a href=&#34;https://en.bitcoin.it/wiki/ASIC&#34;&gt;ASICs&lt;/a&gt; (Application-Specific Integrated Circuits) to stand a chance in this game. Another option is to participate with your home computer as part of a &lt;a href=&#34;https://www.lifewire.com/bitcoin-mining-pools-4158119&#34;&gt;mining pool&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;on-the-ecological-impact-of-bitcoin&#34;&gt;On the ecological impact of Bitcoin&lt;/h1&gt;
&lt;p&gt;This &amp;ldquo;how bitcoin works&amp;rdquo; explanation was written in the context of Bill Gates
stating he was concerned about Bitcoin&amp;rsquo;s ecological impact. While this is the
worst Bitcoin explanation I&amp;rsquo;ve ever read, I don&amp;rsquo;t want to ignore the larger
point of the article. Bitcoin in its current form is harmful for the planet
because of the enormous amount of energy consumed by Proof-of-Work. I tend to
agree with this, and would like to see blockchain networks move towards
Proof-of-Stake (PoS) systems, where validators acquire voting power based on a
pool of money locked as part of the protocol (their &amp;ldquo;stake&amp;rdquo;). Modern networks
are mostly using PoS. Ethereum is also moving to PoS (see
&lt;a href=&#34;https://ethereum.org/en/eth2/staking/&#34;&gt;this&lt;/a&gt; to get started!). Bitcoin should
also move to Proof-of-Stake, although I&amp;rsquo;m not optimistic given how conservative
the Bitcoin community is.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Cloud Archives</title>
      <link>https://arnaudbrousseau.com/notes/cloud-archives.html</link>
      <pubDate>Sat, 20 Jun 2020 11:38:00 -0700</pubDate>
      <guid>https://arnaudbrousseau.com/notes/cloud-archives.html</guid>
      <description>&lt;h1 id=&#34;cloud-archives&#34;&gt;Cloud Archives&lt;/h1&gt;
&lt;p&gt;I&amp;rsquo;ve wanted to dig into my stack of &amp;ldquo;important&amp;rdquo; papers and sort through them
for a while. Why? Because of a moderate to high fear that some will burn, get
damaged or lost in some way, maybe stolen or misplaced. Who knows.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s what I decided to do: archive them all digitally. Let&amp;rsquo;s walk through how.&lt;/p&gt;
&lt;h2 id=&#34;capturing&#34;&gt;Capturing&lt;/h2&gt;
&lt;p&gt;A table with ambiant lighting works best. I use my phone&amp;rsquo;s camera (Pixel 2) to
capture everything.&lt;/p&gt;
&lt;h2 id=&#34;uploading&#34;&gt;Uploading&lt;/h2&gt;
&lt;p&gt;This happens automatically with Google Photos. Nice.&lt;/p&gt;
&lt;h2 id=&#34;archiving&#34;&gt;Archiving&lt;/h2&gt;
&lt;p&gt;I then hop on my laptop (the one I&amp;rsquo;m using to write this), download these
photos, correct for orientation if needed.&lt;/p&gt;
&lt;p&gt;Then I drop these photos into well-named Dropbox folders. To save on space I
use &lt;a href=&#34;https://www.imagemagick.org/Usage/resize/&#34;&gt;ImageMagick&lt;/a&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ magick mogrify -resize 1280x1280\&amp;gt; -quality 80 /Users/arnaud/path/to/dropbox/folder/*.jpg
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The command above resizes all jpg images in the target folder such that they
have a max witdth of 1280px, a max height of 1280px, and a jpeg quality of 80.
This saves a ton of disk space (my Pixel 2 camera spits out images with an
insane quality (typically 3-4MB per picture)&lt;/p&gt;
&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Pretty easy right? Just do it, your future self will thank you.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Has Overwatch become more repetitive? A statistical answer</title>
      <link>https://arnaudbrousseau.com/notes/has-competitive-overwatch-become-more-repetitive-a-statistical-answer.html</link>
      <pubDate>Sun, 12 Jan 2020 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/has-competitive-overwatch-become-more-repetitive-a-statistical-answer.html</guid>
      <description>&lt;script&gt; MathJax = { loader: { load: [&#39;input/asciimath&#39;, &#39;output/chtml&#39;] } }; &lt;/script&gt;
&lt;script type=&#34;text/javascript&#34; src=&#34;https://arnaudbrousseau.com/js/mathjax/tex-chtml.js&#34; id=&#34;MathJax-script&#34; async&gt;&lt;/script&gt;
&lt;p&gt;I&amp;rsquo;m a big fan of &lt;a href=&#34;https://playoverwatch.com&#34;&gt;Overwatch&lt;/a&gt;, Blizzard&amp;rsquo;s FPS. Something about it
keeps calling me back to play, season after season. I&amp;rsquo;ve been playing since the
very first competitive season.&lt;/p&gt;
&lt;p&gt;Lately I&amp;rsquo;ve felt like the game is more repetitive. Teams draw from a reduced
set of heroes. It feels like the same teams face each other. Can we quantify
this with statistics?&lt;/p&gt;
&lt;h2 id=&#34;genesis&#34;&gt;Genesis&lt;/h2&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/overwatch-release.jpg&#34; alt=&#34;Overwatch Release&#34;&gt;&lt;/p&gt;
&lt;p&gt;On May 24th, Overwatch was released with a pool of 21 heroes: Tracer, Reaper,
Widowmaker, Pharah, Reinhardt, Mercy, Torbjörn, Hanzo, Winston, Zenyatta,
Bastion, Symmetra, Zarya, McCree, Soldier: 76, Lúcio, Roadhog, Junkrat, D.Va,
Mei and Genji.&lt;/p&gt;
&lt;p&gt;On June 28th 2016 competitive play is released. Rules are simple: teams
are 6 vs 6, and each player can pick from a pool of 21 heroes. How many
possible teams does that leave us with?&lt;/p&gt;
&lt;p&gt;Assembling an Overwatch team means picking 6 heroes among 21. Since order of
heros doesn&amp;rsquo;t matter we&amp;rsquo;re dealing with a &lt;em&gt;combination&lt;/em&gt; of 6 heroes out of a
set of 21. And since we can pick the same hero multiple times, we&amp;rsquo;re dealing
with a &lt;em&gt;multicombination&lt;/em&gt; (in early competitive overwatch, a team of 6
Winstons was allowed!). In mathematical terms we have a &lt;strong&gt;6-multicombination
from a 21-set&lt;/strong&gt;. Formula for this:&lt;/p&gt;
&lt;p&gt;`(:(:(n),(k):):)=(:(n+k-1),(k):)=((n+k-1)!)/(k!xx(n-1)!)`&lt;/p&gt;
&lt;p&gt;We can compute this for `k=6` and `n=21`:&lt;/p&gt;
&lt;p&gt;`((21 + 6 - 1)!)/(6! xx (21-1)!) = ` &lt;strong&gt;230,230 different teams&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&#34;one-hero-per-team&#34;&gt;One hero per team&lt;/h2&gt;
&lt;p&gt;On July 19th 2016 we went from a system which allowed to pick multiple of the
same heroes to one hero per team. This is actually a fairly significant change!
We are going from multicombination to simple combination with no repetition.
The formula becomes:&lt;/p&gt;
&lt;p&gt;`(:(n),(k):) = ((n!)/(k! xx (n-k)!))`&lt;/p&gt;
&lt;p&gt;Computing this for `k=6` and `n=21`:&lt;/p&gt;
&lt;p&gt;`((21!)/(6! xx (21-6)!)) = ` &lt;strong&gt;54,264 different teams&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Substantial difference indeed! We&amp;rsquo;ve lost 76% of the possible teams compared to what we started with.&lt;/p&gt;
&lt;h2 id=&#34;new-characters-to-the-rescue&#34;&gt;New characters to the rescue!&lt;/h2&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/overwatch-new-heroes.png&#34; alt=&#34;New Overwatch Heroes&#34;&gt;&lt;/p&gt;
&lt;p&gt;Over time Blizzard has added new heroes to the game:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Ana (#22) is added on July 19th 2016. This gives 74,613 teams (&lt;span class=&#34;down&#34;&gt;-67%&lt;/span&gt; compared to genesis)&lt;/li&gt;
&lt;li&gt;Sombra (#23) is added on November 15th 2016: 100,947 teams (&lt;span class=&#34;down&#34;&gt;-56%&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;Orisa (#24) is added on March 21st 2017: 134,596 teams (&lt;span class=&#34;down&#34;&gt;-42%&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;Doomfist (#25) is added on July 27th 2017: 177,100 teams (&lt;span class=&#34;down&#34;&gt;-23%&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;Moira (#26) is added on November 16th 2017: 230,230 teams (&lt;em&gt;same than genesis exactly!&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;Brigitte (#27) is added on March 20th 2018: 296,010 teams (&lt;span class=&#34;up&#34;&gt;+29%&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;Wrecking Ball (#28) is added on July 24th 2018: 376,740 teams (&lt;span class=&#34;up&#34;&gt;+64%&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;Ashe (#29) is added on November 13th 2018: 475,020 teams (&lt;span class=&#34;up&#34;&gt;+106%&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;Baptiste (#30) is added on March 19th 2019: 593,775 teams (&lt;span class=&#34;up&#34;&gt;+158%&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;Sigma (#29) is added on August 13th 2019: 736,281 teams (&lt;span class=&#34;up&#34;&gt;+220%&lt;/span&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I was surprised/pleased to see how much new heroes contributed to the overall
complexity of the game. We&amp;rsquo;ve had almost 2 years (Nov 2017 to Sept 2019) during
which the game was &lt;strong&gt;more&lt;/strong&gt; complex than when it was released, despite the new
&amp;ldquo;one hero per team&amp;rdquo; restriction.&lt;/p&gt;
&lt;h2 id=&#34;enters-role-queue&#34;&gt;Enters Role Queue&lt;/h2&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/overwatch-role-queue.jpg&#34; alt=&#34;Overwatch Role Queue&#34;&gt;&lt;/p&gt;
&lt;p&gt;On September 1st 2019 Blizzard launched Role Queue, a system which enforces a
2-2-2 composition for competitive teams. 2 tank, 2 damage, and 2 support
heroes. How does this affect the possible teams? Let&amp;rsquo;s find out.&lt;/p&gt;
&lt;p&gt;The 31 heroes are divided as follow:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;8 tank heroes: D.Va, Orisa, Reinhardt, Roadhog , Sigma, Winston, Wrecking Ball, Zarya&lt;/li&gt;
&lt;li&gt;16 damage characters: Ashe, Bastion, Doomfist, Genji, Hanzo, Junkrat, McCree, Mei, Pharah, Reaper, Soldier: 76, Sombra, Symmetra, Torbjörn, Tracer, Widowmaker&lt;/li&gt;
&lt;li&gt;7 support characters: Ana, Baptiste, Brigitte, Lúcio, Mercy, Moira, Zenyatta&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A competitive team is now defined by 3 sub-teams. Each sub-team is a
2-combination. And the 3 sub-teams can be combined independently (no
restriction). So, if X, Y and Z are the number of sub-teams for each hero
class, the number of competitive teams is `X xx Y xx Z`.&lt;/p&gt;
&lt;p&gt;Number of teams ` = (:(8),(2):) xx (:(16),(2):) xx (:(7),(2):) = ` 70,560 (-70%)&lt;/p&gt;
&lt;p&gt;Pretty big dip in complexity!&lt;/p&gt;
&lt;p&gt;Fun fact: if we had an even split (10 tank, 11 damage, and 10 support heroes) we&amp;rsquo;d have 111,375 possible teams instead of ~70k.&lt;/p&gt;
&lt;p&gt;Another fun thought: to get back to the initial number of possible teams
(~230k), we&amp;rsquo;d need 5 extra heroes in support/tank (giving 10/16/10 for
tank/damage/support counts) or&amp;hellip;&lt;em&gt;13 extra damage heroes&lt;/em&gt; if we keep support/tank
pools at their current capacity (giving 8/29/7 for tank/damage/support).&lt;/p&gt;
&lt;p&gt;The limiting factor in complexity right now is the disproportionately small
pool of support and tank heroes.&lt;/p&gt;
&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Until now I didn&amp;rsquo;t realize how much new heroes contributed to the overall
complexity of Overwatch. My initial feeling as a player is not backed by
statistics. There was big chunk of time during which the game was significantly
&lt;strong&gt;more&lt;/strong&gt; complex than when it launched due to new heroes added.&lt;/p&gt;
&lt;p&gt;What statistics did confirm however: the introduction of Role Queue caused the
number of possible teams to go drastically down. That&amp;rsquo;s not a bad thing
necessarily: many team compositions outside of 2-2-2 weren&amp;rsquo;t viable for
competitive play. But it does make the game more repetitive. We&amp;rsquo;ll have to wait
until Blizzard introduces a few new heroes to experience higher levels of
complexity once again. Or maybe another game will come first&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/overwatch-2.jpg&#34; alt=&#34;Overwatch 2&#34;&gt;&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Feeling Lucky? How-to: Steal Bitcoins</title>
      <link>https://arnaudbrousseau.com/notes/feeling-lucky-how-to-steal-bitcoins.html</link>
      <pubDate>Fri, 13 Sep 2019 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/feeling-lucky-how-to-steal-bitcoins.html</guid>
      <description>&lt;p&gt;Get this: all of the Bitcoin private keys are currently out there, in the open.
What you need to steal coins right now: a insane amount of luck and the
knowledge to exploit it. I can&amp;rsquo;t help with the luck part, but I&amp;rsquo;ll arm you with
knowledge.&lt;/p&gt;
&lt;h2 id=&#34;steal-what&#34;&gt;Steal what?&lt;/h2&gt;
&lt;p&gt;I&amp;rsquo;m assuming you&amp;rsquo;re familiar with &lt;a href=&#34;https://bitcoin.org/en/&#34;&gt;Bitcoin&lt;/a&gt;, the most popular (and
first) cryptocurrency, created by Satoshi Nakamoto in 2009. A Bitcoin &amp;ldquo;wallet&amp;rdquo;
is nothing more than a random number, kept private (&amp;ldquo;private&amp;rdquo; key).  This
number is then used to generate another number (your &amp;ldquo;public&amp;rdquo; key). This is
considered secure because a private key is picked from an extremely big range:
from 1 to 2^256 (see next section for a good explanation on how big 2^256 is).
So it&amp;rsquo;s unlikely that you and me pick the same private key when we choose one
randomly.&lt;/p&gt;
&lt;p&gt;What about random luck though? What if you happen to pick the same private key
than me? If you do, my money is essentially yours.&lt;/p&gt;
&lt;p&gt;If you happen to pick the same private key than Satoshi Nakamoto when (s)he
mined the first block, you&amp;rsquo;ll be famous but not that rich.
&lt;code&gt;1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa&lt;/code&gt; (genesis public key) currently holds 68 BTC
(~$500k). Not bad. If you happen the pick the same private key than one of
&lt;a href=&#34;https://bitinfocharts.com/top-100-richest-bitcoin-addresses.html&#34;&gt;these people&lt;/a&gt;, however: congratulations, you&amp;rsquo;re a
billionnaire.&lt;/p&gt;
&lt;h2 id=&#34;what-are-my-odds&#34;&gt;What are my odds?&lt;/h2&gt;
&lt;p&gt;In short: close to nothing. More precisely, if you&amp;rsquo;re targetting a particular
address, your odds are: 1 over&amp;hellip;&lt;/p&gt;
&lt;code style=&#34;font-size:11px&#34;&gt;
115,792,089,237,316,195,423,570,985,008,687,907,853,269,984,665,640,564,039,457,584,007,913,129,639,936
&lt;/code&gt;&lt;br&gt;
&lt;small&gt;(that&#39;s the decimal notation for 2^256)&lt;/small&gt;
&lt;p&gt;This number is big. Mind-boggling big. The following YouTube video attempts to explain this:&lt;/p&gt;
&lt;iframe width=&#34;560&#34; height=&#34;315&#34; src=&#34;https://www.youtube.com/embed/S9JGmA5_unY&#34; frameborder=&#34;0&#34; allow=&#34;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&#34; allowfullscreen&gt;&lt;/iframe&gt;
&lt;p&gt;While your odds are close to nothing it&amp;rsquo;s still worth asking the question:
&amp;ldquo;what if?&amp;rdquo;. Assuming you randomly pick the same private key than a weathly
Bitcoin wallet, how do you make them yours?&lt;/p&gt;
&lt;h2 id=&#34;enters-keyslol&#34;&gt;Enters &lt;code&gt;keys.lol&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Since all Bitcoin private keys are known and easy to enumerate, Sjors Ottjes
created &lt;a href=&#34;https://keys.lol/&#34;&gt;keys.lol&lt;/a&gt;, a directory of all the Bitcoin keys in existence:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/keys.lol.png&#34; alt=&#34;keys.lol homepage&#34;&gt;&lt;/p&gt;
&lt;p&gt;This website displays random batches of 128 Bitcoin keys and whether they hold
unspent coins, by talking to a 3rd party API. Go ahead: click the &amp;ldquo;Random page&amp;rdquo;
button on the homepage. You have a shot at landing on the page where Satoshi&amp;rsquo;s
private key is listed. Exciting isn&amp;rsquo;t it?&lt;/p&gt;
&lt;h2 id=&#34;ive-found-an-active-key-now-what&#34;&gt;I&amp;rsquo;ve found an active key! Now what?&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s redeem your prize! Unspent Bitcoins on the network are called &amp;ldquo;Unspent
transaction outputs&amp;rdquo;, or UTXO. If you found a UTXO attributed to a public key
listed on keys.lol, you know the associated private key. Hence you can &amp;ldquo;steal&amp;rdquo;
the associated coins (aka UTXOs) and move them under the control of another
private key only you know.&lt;/p&gt;
&lt;p&gt;To do this you need to send a transaction to the Bitcoin network, signed by the
initial private key (the one you found on keys.lol), which moves one or more
UTXOs to a new public key. Naturally, this new public key will be controlled by
another private key, and known only by you!&lt;/p&gt;
&lt;p&gt;A great website to do this is &lt;a href=&#34;https://coinb.in/#newTransaction&#34;&gt;coinb.in&lt;/a&gt;. If you were to stumble upon
satoshi&amp;rsquo;s private key, here&amp;rsquo;s how you&amp;rsquo;d generate a modest transaction
transfering 0.001 BTC ($7) to another address:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/coinb.in.png&#34; alt=&#34;coinb.in transaction&#34;&gt;&lt;/p&gt;
&lt;p&gt;Then use the signing utility to sign the transaction:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/coinb.in.signature.png&#34; alt=&#34;coinb.in signature&#34;&gt;&lt;/p&gt;
&lt;p&gt;Then use their free broadcasting tool to submit this transaction on the Bitcoin
network. Congratulations!&lt;/p&gt;
&lt;h2 id=&#34;dont-trust-verify&#34;&gt;Don&amp;rsquo;t trust, verify&lt;/h2&gt;
&lt;p&gt;When I first learned about keys.lol I immediately thought:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How does this work at a high level? How to you go from page and offset to a seed, then to a private key? Which formats is the site using?&lt;/li&gt;
&lt;li&gt;Can I recover a page and offset from a known private key?&lt;/li&gt;
&lt;li&gt;Is it safe? What if I display my own private key? Does this website log anything?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With this in mind I started re-implementing public key crypto (a very basic
subset of it!) and keys.lol&amp;rsquo;s functionality in JavaScript. Enters:
&lt;code&gt;keys.deconstructed&lt;/code&gt;, a webapp which works offline and has &lt;strong&gt;zero external
dependencies&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/keys.deconstructed-ui.png&#34; alt=&#34;keys.deconstructed UI&#34;&gt;&lt;/p&gt;
&lt;p&gt;→ &lt;a href=&#34;https://arnaudbrousseau.com/labs/keys.deconstructed&#34;&gt;keys.deconstructed&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Coding the above toy app I learned that keys.lol generates seed from page and
offset using &lt;code&gt;seed = (page - 1) * 128 + offset&lt;/code&gt;. From that seed, an
uncompressed private key is generated, and two public keys (both compressed and
uncompressed are generated). This sounds complex but it can be done in ~500
lines of code! Here&amp;rsquo;s the code: &lt;a href=&#34;https://github.com/ArnaudBrousseau/arnaudbrousseau.com/blob/master/static/labs/keys.deconstructed/keys.deconstructed.js&#34;&gt;keys.deconstructed.js&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Another feature I built is going the reverse route: from a known WIF
uncompressed private key, recover the seed, then compute the page/offset on
keys.lol. This is useful if you want to view your own addresses.&lt;/p&gt;
&lt;p&gt;Going the other route (page/offet, to seed, to private key) lets me
double-check what keys.lol displays, and ensures that the private key displayed
on the site is indeed the private key controlling the public keys listed there.&lt;/p&gt;
&lt;p&gt;This leaves us with one question: does keys.lol log anything when I view keys
with unspent transaction outputs?&lt;/p&gt;
&lt;h2 id=&#34;honeypot&#34;&gt;Honeypot&lt;/h2&gt;
&lt;p&gt;I generated a random page number between 0 and 9046..6675
(total number of pages) and sent 0.001 BTC to one of the public keys listed
there (I picked &lt;code&gt;1A2zNEFyMAfmZdy4yeXUoaPdt5Kns6vu3s&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Then I visited the keys.lol page where this address appears. If the site owner
logs anything, we should see the coins move at some point. I&amp;rsquo;ve obscured the
private keys, but there you have it: a green key on keys.lol!&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/keys.lol.honeypot.png&#34; alt=&#34;keys.lol honeypot&#34;&gt;&lt;/p&gt;
&lt;p&gt;Now the question is: was this logged in any way? Here&amp;rsquo;s a link to the public
key so you can monitor this with me:
&lt;a href=&#34;https://www.blockchain.com/btc/address/1A2zNEFyMAfmZdy4yeXUoaPdt5Kns6vu3s&#34;&gt;1A2zNEFyMAfmZdy4yeXUoaPdt5Kns6vu3s&lt;/a&gt;.
If we see these coins move: keys.lol is rigged. Time will tell. Please email
or tweet at me if you see something!&lt;/p&gt;
&lt;center&gt;&lt;em&gt;(2022-09-18) Update, 3+ years later: the coins have not moved yet! Hence keys.lol is most likely not rigged.&lt;/em&gt;&lt;/center&gt;
</description>
    </item>
    <item>
      <title>What I Learned at BuildEth 2019</title>
      <link>https://arnaudbrousseau.com/notes/what-i-learned-at-buildeth-2019.html</link>
      <pubDate>Fri, 19 Jul 2019 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/what-i-learned-at-buildeth-2019.html</guid>
      <description>&lt;h2 id=&#34;the-state-of-the-ethereum-network-scott-bigelow-amberdata&#34;&gt;The State of the Ethereum Network (Scott Bigelow, Amberdata)&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;https://amberdata.io/&#34;&gt;Amberdata&lt;/a&gt; is a tool keeping track of trends on the Ethereum network:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;on average the network burns throough 40B unit of gas per day&lt;/li&gt;
&lt;li&gt;contract calls are getting deeper and deeper&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://2018.ethereuminreview.com/&#34;&gt;https://2018.ethereuminreview.com/&lt;/a&gt; for a full list&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Dapps have become more tightly integrated together&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://uniswap.io/&#34;&gt;uniswap&lt;/a&gt; is a protocol to exchange anything in a decentralized way&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.pooltogether.us/&#34;&gt;Pooltogether.us&lt;/a&gt; is a &amp;ldquo;lossless&amp;rdquo; lottery, built on top of
&lt;a href=&#34;https://compound.finance/&#34;&gt;Compound.finance&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://makerdao.com/&#34;&gt;MakerDAO&lt;/a&gt; interacts with more and more assets types&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://0x.org/&#34;&gt;0x&lt;/a&gt; is a decentralized exchange leveraging uniswap and other protocols&lt;/li&gt;
&lt;li&gt;Because of ERC721 you can now wrap your Cryptokitties and swap them in a decentralized way&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;the-state-of-the-community-grant-hummer-chromatic-capital&#34;&gt;The State of the Community (Grant Hummer, Chromatic Capital)&lt;/h2&gt;
&lt;p&gt;User community is not there yet for Ethereum. Today there&amp;rsquo;s barely  20,000
users per day across all dapps. The most popular dapps see 1,000 users per day.
This is ridiculously low by web standards.&lt;/p&gt;
&lt;p&gt;DeFi is the exception! It has the potential to attract a lot of users because
of the use cases it unlocks.&lt;/p&gt;
&lt;p&gt;Dev community is healthy, with 1.3M users on Meetups. EthGlobal hackathons are
blooming. Investors are the least important part of the community.&lt;/p&gt;
&lt;h2 id=&#34;the-ethereum-foundation-albert-ni-ethereum-foundation&#34;&gt;The Ethereum Foundation (Albert Ni, Ethereum Foundation)&lt;/h2&gt;
&lt;p&gt;Nothing really important to note here except one quote and one book. Quote:
&amp;ldquo;Coherence is not completeness&amp;rdquo;. Which we can interpret as: it&amp;rsquo;s easier to have
a strong opinion with less information.&lt;/p&gt;
&lt;p&gt;And one book: &lt;a href=&#34;https://www.amazon.com/gp/product/1781256179&#34;&gt;Good Strategy Bad Strategy&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;a-tour-of-the-dapp-landscape-orest-byskosh-ausum-ventures&#34;&gt;A Tour of the DApp Landscape (Orest Byskosh, Ausum Ventures)&lt;/h2&gt;
&lt;p&gt;This was more or less an inventory of all the interesting dapps out there.&lt;/p&gt;
&lt;p&gt;Did you know? &lt;a href=&#34;https://en.wikipedia.org/wiki/Nick_Szabo&#34;&gt;Nick Szabo&lt;/a&gt; coined the term smart contract. From inception to August 2018, over 28B dollars have been raised.&lt;/p&gt;
&lt;p&gt;Collectibles:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.cryptokitties.co&#34;&gt;CryptoKitties&lt;/a&gt; (126 users/day)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://superrare.co/&#34;&gt;SuperRare&lt;/a&gt; (10 users/day)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://opensea.io/&#34;&gt;OpenSea&lt;/a&gt; (148 users/day)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.auctionity.com/&#34;&gt;Auctionity&lt;/a&gt; (149 users/day)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Games and gambling are significantly more successful with users:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.wink.org&#34;&gt;TRONbet/Wink&lt;/a&gt; (3.7k users/day)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.mycryptoheroes.net/&#34;&gt;My crypto heroes&lt;/a&gt; (2.7k users/day)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://dice.one/&#34;&gt;Dice&lt;/a&gt; (2.2k users/day)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Decentralized finance:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://0x.org/&#34;&gt;0x&lt;/a&gt; sees 700k txs/day&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://idex.market/&#34;&gt;IDEX&lt;/a&gt; has 1,000 users/day&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://kyber.network/&#34;&gt;Kyber&lt;/a&gt; (350 users per day)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://uniswap.io/&#34;&gt;Uniswap&lt;/a&gt; (2,000 ETH in daily volume)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.bancor.network/token/DAPP&#34;&gt;Bancor&lt;/a&gt; (300 transactions/day)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;wallets-uxui-and-more-austin-griffith-burner-wallet&#34;&gt;Wallets, UX/UI, and More (Austin Griffith, Burner Wallet)&lt;/h2&gt;
&lt;p&gt;Several interesting concepts here:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/austintgriffith/bouncer-proxy&#34;&gt;Bouncer proxies&lt;/a&gt; let users interact with smart contracts
without holding ETH. This is often a big source of friction. This lets a
proxy gas transactions on behalf of users.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/austintgriffith/burner-wallet&#34;&gt;Burner wallets&lt;/a&gt; is a quick way to generate keys in-browser.
This is ideal from small transactions. This has been &lt;a href=&#34;https://medium.com/gitcoin/how-to-host-a-burner-wallet-event-53a429035a24&#34;&gt;proven to work&lt;/a&gt;!&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;the-finality-gadget-putting-eth2-to-work-alex-stokes-ethereum-foundation&#34;&gt;The Finality Gadget: Putting ETH2 to Work (Alex Stokes, Ethereum Foundation)&lt;/h2&gt;
&lt;p&gt;This talk went over my head a bit, forgive me for the rough notes.&lt;/p&gt;
&lt;p&gt;ETH 2.0 rollout will happen in 3 phases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Phase 0: beacon chain&lt;/li&gt;
&lt;li&gt;Phase 1: shard data chains&lt;/li&gt;
&lt;li&gt;Phase 2: shard application chains&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Phase 0 (beacon chain): beacon chain is a systel-level blockchain. Along with
beacon chain, Casper (PoS consensus) is being rolled out. Empty references to
shards are being dropped.&lt;/p&gt;
&lt;p&gt;Phase 1: 1024 shards are being added to shard data. Blocks just have 16kb of
random data. Canonical shards are crosslinked into the beacon chain.&lt;/p&gt;
&lt;p&gt;Phase 2: eWASM VM, flexible execution environments, and sharding of application
chains&lt;/p&gt;
&lt;p&gt;Ethereum 1.x can be improved today without waiting for ETH2.0. One of these things is Finality Gadget.&lt;/p&gt;
&lt;p&gt;Finality Gadget (part of Casper):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;in the normal case, validators attest to blocks in the canonical chain&lt;/li&gt;
&lt;li&gt;if more than 2/3rd of validators attest to a given block, it is justified&lt;/li&gt;
&lt;li&gt;if validators make two successive justifications, then the first justified
block is finalized&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Under normal conditions ETH1.0 block hashes enter the beacon chain with every
beacon block. The casper consensus finalizes these beacon blocks. if an ETH1.0
block hash is finalized on the beacon chain, then every block beneath it in on
the ETH 1.0 chain is implicitly finalized as well.&lt;/p&gt;
&lt;p&gt;More details are available in &lt;a href=&#34;https://medium.com/@ralexstokes/the-finality-gadget-2bf608529e50&#34;&gt;this blog post&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;how-we-developed-the-eth2-client-terence-tsao-prysmatic-labs&#34;&gt;How We Developed the ETH2 Client (Terence Tsao, Prysmatic Labs)&lt;/h2&gt;
&lt;p&gt;This talk wasn&amp;rsquo;t very dense. Takeaways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We need standards! &lt;a href=&#34;https://medium.com/@ralexstokes/the-finality-gadget-2bf608529e50&#34;&gt;Link to in-progress specs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Ethereum 2.0 has two parts: the beacon node (which maintains the state of the beacon chain, communicates with other beacon nodes, and responds to validator client queries), and the validator client (which maintains private / sensitive data &amp;amp; query beacon nodes to perform validator duties)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;using-randomness-in-smart-contracts-haseeb-qureshi-metastable&#34;&gt;Using Randomness in Smart Contracts (Haseeb Qureshi, Metastable)&lt;/h2&gt;
&lt;p&gt;Really interesting session. The first idea is that the blockchain itself does
not have good solutions for sources of randomness:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;blockhashes aren&amp;rsquo;t random enough. Given enough financial incentive miners can
discard/keep hashes that are advantageous to them&lt;/li&gt;
&lt;li&gt;off-chain beacons are expensive&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.randao.org/&#34;&gt;RANDAO&lt;/a&gt; is a nice distributed scheme where actors
summit numbers in a decentralized way. However this scheme suffers from the
&amp;ldquo;last actor&amp;rdquo; problem: what if the person who goes last does not want to
reveal their number based on what they&amp;rsquo;re seeing so far? They can force a
discard and influence the outcome.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;VDFs (Verifiable Delay Functions) are hard function that can only be computed
sequentially (not parallelizable). Example: iterative hashing. Iterative
hashing is a VDF but cannot be verified easily (to verify the output, the
verifier has to compute the iterative hashes).&lt;/p&gt;
&lt;p&gt;Final solution: &lt;code&gt;f(D, N1 ^ N2 ^ N3 ...)&lt;/code&gt;. See also &lt;a href=&#34;https://nearprotocol.com/blog/randomness-in-blockchain-protocols/&#34;&gt;NEAR&amp;rsquo;s article on
randomness&lt;/a&gt;, which explores these notions and goes a step
further.&lt;/p&gt;
&lt;h2 id=&#34;writing-smart-contracts-with-zk-proofs-elena-nadolinski-beanstalk-network&#34;&gt;Writing Smart Contracts with ZK Proofs (Elena Nadolinski, Beanstalk Network)&lt;/h2&gt;
&lt;p&gt;Very good talk. &lt;a href=&#34;https://docs.google.com/presentation/d/1-QB6DAHliQRAUW5rdCqSRQ_w6W2yGTidB61UWzq_p20&#34;&gt;Link to slides&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;What are ZKPs? (Zero-Knowledge Proofs). It&amp;rsquo;s a system to reveal knowledge of a
solution to a probem without revealing the solution itself. For instance, if I
want to reveal the knowledge of a solution to a &amp;ldquo;where is Waldo&amp;rdquo; problem, I can
take a close-up picture of Waldo without any surrounding context to prove that
I know where he is. But that doesn&amp;rsquo;t reveal his location on the page.&lt;/p&gt;
&lt;p&gt;ZKPs are different from privacy. ZKPs, fundamentally, are computation proofs.
In math terms, if &lt;code&gt;f(x) = y&lt;/code&gt;, ZKPs are a way to reveal a proof and &lt;code&gt;y&lt;/code&gt;, without
revealing &lt;code&gt;x&lt;/code&gt;, to convince somebody that I&amp;rsquo;ve done computation &lt;code&gt;f&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;ZKPs have a lot of possible applications:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;credit card score reveal (proving that it&amp;rsquo;s more than 700, without revealing
its exact value)&lt;/li&gt;
&lt;li&gt;proving that my dna is in this set, without revealing my genes&lt;/li&gt;
&lt;li&gt;proving that I made a tx with this account, without revealing the tx itself&lt;/li&gt;
&lt;li&gt;proving that I&amp;rsquo;m a part of a group which can access this website (without
revealing who I am)&lt;/li&gt;
&lt;li&gt;proving that a computer has made honest computation&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;ZKPs come in different flavors:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;zk-SNARKSs (most popular, more than 50+ variations, some quantum secure). Size: 288 bytes, prover time: 2.3s, verification time: 10ms&lt;/li&gt;
&lt;li&gt;zk-STARKs (newer). Size: 45Kb-200Kb, prover time: 1.6s, verification time: 16ms&lt;/li&gt;
&lt;li&gt;bulletproofs (coming from Stanford). Stellar is working on improvements. Right now size is at 1.3kb, prover time is 30s, and verification time is 1100ms&lt;/li&gt;
&lt;li&gt;Sonic&lt;/li&gt;
&lt;li&gt;Aurora&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Projects using ZKPs:
Coda, beanstalk (privacy coin), 0x, Zcash, monero. Matter&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://codaprotocol.com/&#34;&gt;Coda&lt;/a&gt; is a blockchain where &lt;code&gt;x&lt;/code&gt; is the entire history &lt;code&gt;f&lt;/code&gt; is how the
chain progresses. This chain progresses by &amp;ldquo;proof inception&amp;rdquo; (a proof which
proves that a proof which proves that a proof&amp;hellip;is true.)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.beanstalk.network/&#34;&gt;Beanstalk&lt;/a&gt; (privacy coin)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://0x.org/&#34;&gt;0x&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://z.cash/&#34;&gt;Zcash&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.getmonero.org/&#34;&gt;Monero&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Tooling for SNARKS:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/Zokrates/ZoKrates&#34;&gt;Zokrates&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/zkcrypto/bellman&#34;&gt;bellman&lt;/a&gt; (Rust implementation)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/o1-labs/snarky&#34;&gt;snarky&lt;/a&gt; (OCaml)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/scipr-lab/libsnark&#34;&gt;libsnark&lt;/a&gt; (C++)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/iden3/circom&#34;&gt;Circom&lt;/a&gt; and &lt;a href=&#34;https://github.com/iden3/snarkjs&#34;&gt;snarkjs&lt;/a&gt; (JS)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/arnaucube/go-snark&#34;&gt;go-snark&lt;/a&gt; (Golang)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Tooling for STARKs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/elibensasson/libSTARK&#34;&gt;libSTARK&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/wolkdb/deepblockchains/tree/master/stark&#34;&gt;experimental Go implementation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Tooling for Bulletproofs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/dalek-cryptography/bulletproofs&#34;&gt;Ristretto&lt;/a&gt; (Rust implementation)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/bbuenz/BulletProofLib&#34;&gt;BulletProofLib&lt;/a&gt;, Benedikt&amp;rsquo;s Bunzz Java implementation&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;What&amp;rsquo;s easiest to start with&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://arxiv.org/pdf/1906.07221.pdf&#34;&gt;Why and How zk-SNARK Works: Definitive Explanation&lt;/a&gt;
(great PDF going in-depth on the foundations of zk-SNARKs)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/Zokrates/ZoKrates&#34;&gt;Zokrates&lt;/a&gt;, &lt;a href=&#34;https://github.com/iden3/snarkjs&#34;&gt;snarkjs&lt;/a&gt;, &lt;a href=&#34;https://github.com/HarryR/ethsnarks&#34;&gt;ETHSnarks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/matter-labs/Edcon2019_material&#34;&gt;This tutorial&lt;/a&gt; by Matter Labs&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/kobigurk/semaphore&#34;&gt;sempahore&lt;/a&gt;. Try to prove that you&amp;rsquo;re part of a company and make a
statement without revealing who you are!&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;geofencing-with-erc-1404-mason-borda-tokensoft&#34;&gt;Geofencing with ERC 1404 (Mason Borda, TokenSoft)&lt;/h2&gt;
&lt;p&gt;Interesting talk, mostly because I work for Coinbase Custody and ERC20
regulation is relevant. The speaker is a Tokensoft employee. Their clients:
Hedera (Hashgraph), Tezos, tokenized funds, real estate and more. They&amp;rsquo;ve got
more than 30 clients at the moment&lt;/p&gt;
&lt;p&gt;Their approach is to treat all ERC20s as a security token, asset-backed or not.
The need for a standard comes from banking regulations (KYC/AML), securities
laws, tax regulations (more specifically regulation S and D).&lt;/p&gt;
&lt;p&gt;One specific regulation that&amp;rsquo;s hard to comply with on the Ethereum blockchain
is the distribution compliance period, during which tokens cannot cross
borders. &lt;a href=&#34;https://erc1404.org/&#34;&gt;ERC 1404&lt;/a&gt; helps with tracking this.&lt;/p&gt;
&lt;p&gt;Other things possible with ERC1404:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;set maximum ownership&lt;/li&gt;
&lt;li&gt;revocability&lt;/li&gt;
&lt;li&gt;administrators&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;wallet-interoperability-myungin-lee-and-alex-patin-squarelink&#34;&gt;Wallet Interoperability (Myungin Lee and Alex Patin, Squarelink)&lt;/h2&gt;
&lt;p&gt;Pretty dull discussion overall. The main problem is discoverability. We talked
about &lt;a href=&#34;https://squarelink.com/&#34;&gt;Squarelink&lt;/a&gt; and how it approaches the problem, but never
talked about concrete solutions.&lt;/p&gt;
&lt;h2 id=&#34;py-evm-reinventing-sync-is-easier-than-optimizing-python-jason-carver-ethereum-foundation&#34;&gt;PY-EVM: Reinventing Sync is Easier than Optimizing Python (Jason Carver, Ethereum Foundation)&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;https://trinity.ethereum.org/&#34;&gt;Trinity&lt;/a&gt; is the Python client for the ethereum blockchain, powered by
&lt;a href=&#34;https://github.com/ethereum/py-evm&#34;&gt;py-evm&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This talk was about the different strategies for syncing a node. This isn&amp;rsquo;t
something I&amp;rsquo;ve given a lot of thought before. There&amp;rsquo;s &amp;ldquo;regular sync&amp;rdquo;, &amp;ldquo;fast
sync&amp;rdquo;, and &amp;ldquo;beam sync&amp;rdquo;. &amp;ldquo;Beam sync&amp;rdquo; is a new syncing strategy.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Regular sync&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Begin at genesis&lt;/li&gt;
&lt;li&gt;Execute transactions in block, locally generate state&lt;/li&gt;
&lt;li&gt;Repeat until you reach tip&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Fast sync&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;SKIP execution until the most-recent head&lt;/li&gt;
&lt;li&gt;Download state from that head, then go from there.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Bottlenecks for fast sync are account/storage download. The chain progresses
forward while download is happening, and peers might drop old roots (happens
every 100 blocks or so).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Beam sync&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;SKIP execution until the most-recent head&lt;/li&gt;
&lt;li&gt;Start up without state (no download!)&lt;/li&gt;
&lt;li&gt;Execute blocks, and request on &amp;ldquo;data fault&amp;rdquo;&lt;/li&gt;
&lt;li&gt;Keep requested and generated state&lt;/li&gt;
&lt;li&gt;Repeat as the chain moves forward&lt;/li&gt;
&lt;li&gt;A typical mainnet block requires 3000 state trie nodes for execution&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The main benefit here is that all beam-syncing peers will download the same
trie nodes. There&amp;rsquo;s a big caching opportunity.&lt;/p&gt;
&lt;h2 id=&#34;ethereum-name-service-as-a-ux-solution-brantly-millegan-ethereum-name-service&#34;&gt;Ethereum Name Service as a UX Solution (Brantly Millegan, Ethereum Name Service)&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;https://www.namecoin.org/&#34;&gt;Namecoin&lt;/a&gt; (.bit) is a blockchain just dedicated to naming. &lt;a href=&#34;https://ens.domains/&#34;&gt;Ethereum
Name Service&lt;/a&gt; (ENS) is a smart contract dedicated to naming, built on top
of Ethereum.&lt;/p&gt;
&lt;p&gt;Unlike DNS, ENS has no servers! It&amp;rsquo;s entirely based on smart contracts. It&amp;rsquo;s
been integrated into a ton of wallet apps and even browsers! Typing
&lt;code&gt;somename.eth&lt;/code&gt; in opera &amp;ldquo;just works&amp;rdquo; and loads IPFS websites. For browsers
which do not support &lt;code&gt;.eth&lt;/code&gt; directly, &lt;code&gt;.eth.link&lt;/code&gt; is a compatibility layer to
load IPFS websites. Example: &lt;a href=&#34;http://almonit.eth.link/&#34;&gt;http://almonit.eth.link/&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;in-closing&#34;&gt;In closing&lt;/h2&gt;
&lt;p&gt;Super high-quality conference for the price that it cost (I paid $75 for my
ticket!). I&amp;rsquo;d highly recommend it for people who want to get more familiar with
the Ethereum ecosystem/community.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Don&#39;t fear Libra. Fear Facebook</title>
      <link>https://arnaudbrousseau.com/notes/do-not-fear-libra-fear-facebook.html</link>
      <pubDate>Tue, 25 Jun 2019 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/do-not-fear-libra-fear-facebook.html</guid>
      <description>&lt;p&gt;I read &lt;a href=&#34;https://arnaudbrousseau.com/pdfs/the-libra-blockchain.pdf&#34;&gt;The Libra Blockchain&lt;/a&gt; (this link is a hosted version of
what can be found at &lt;a href=&#34;https://developers.libra.org/docs/assets/papers/the-libra-blockchain.pdf&#34;&gt;this live URL&lt;/a&gt;) to make up my mind about Facebook&amp;rsquo;s new cryptocurrency, Libra.&lt;/p&gt;
&lt;h2 id=&#34;too-long-didnt-read&#34;&gt;Too Long; Didn&amp;rsquo;t Read&lt;/h2&gt;
&lt;p&gt;What I want you to take away: Libra is boring. It&amp;rsquo;s a simple cryptocurrency
composed of well-known, battle-tested components.&lt;/p&gt;
&lt;p&gt;I also want to convince you that if users transact through Facebook products
like Whatsapp or Messenger they are doomed to leak a lot of valuable data to
Facebook. No matter what (crypto)currency Facebook adopts.&lt;/p&gt;
&lt;h2 id=&#34;libra-overview&#34;&gt;Libra Overview&lt;/h2&gt;
&lt;h3 id=&#34;main-components&#34;&gt;Main Components&lt;/h3&gt;
&lt;p&gt;Libra is a permissioned proof-of-stake blockchain. &amp;ldquo;Permissioned&amp;rdquo; because only
Libra Association members can run validator nodes (long-term Libra might shift
towards a permission-less system, but that&amp;rsquo;s not the case right now).&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Validators&amp;rdquo; are nodes which produce new blocks. A block is an aggregation of
user transactions. User accounts are backed by public/private key pairs, and
transactions are based on smart contracts. Smart contracts use a new Language
called &amp;ldquo;Move&amp;rdquo;.&lt;/p&gt;
&lt;h3 id=&#34;libra-blockchain-vs-protocol-vs-core&#34;&gt;Libra Blockchain vs Protocol vs Core&lt;/h3&gt;
&lt;p&gt;In the paper we see a distinction drawn between &amp;ldquo;Libra Blockchain&amp;rdquo;, &amp;ldquo;Libra
Protocol&amp;rdquo; and &amp;ldquo;Libra Core&amp;rdquo;. Until proven otherwise Libra Core will probably be
the only implementation of the Libra Protocol. And the Libra Protocol will
probably be the only protocol for the Libra Blockchain. Enough already.&lt;/p&gt;
&lt;h3 id=&#34;cryptography&#34;&gt;Cryptography&lt;/h3&gt;
&lt;p&gt;Libra&amp;rsquo;s hash function of choice is &lt;a href=&#34;https://en.wikipedia.org/wiki/SHA-3&#34;&gt;SHA3-256&lt;/a&gt;. The keys/signatures
use EdDSA (&lt;a href=&#34;https://en.wikipedia.org/wiki/EdDSA#Ed25519&#34;&gt;Ed25519 curve&lt;/a&gt;). These are standard, unsurprising
decisions (Stellar also uses Ed25519)&lt;/p&gt;
&lt;p&gt;Once a public/private key pair is generated, Libra has a &lt;code&gt;create_account&lt;/code&gt;
operation (similar to Stellar!).&lt;/p&gt;
&lt;p&gt;Libra also supports changing an account&amp;rsquo;s underlying Ed25519 key pair without
changing its Libra public key (similar to Stellar!!&amp;hellip;spotting a theme yet?)&lt;/p&gt;
&lt;h3 id=&#34;transactions&#34;&gt;Transactions&lt;/h3&gt;
&lt;p&gt;In Libra transaction execution and smart contract calls are one and the same.
Smart contracts closely follow what Ethereum does (concept of code to execute,
gas price, gas cost).&lt;/p&gt;
&lt;p&gt;Each transaction has a sender address/pubkey, a program, a gas price, a max gas
amount and a sequence number. It&amp;rsquo;s basically exactly the same than Ethereum
except that all transactions are smart contract calls (including raw
send/receive operations)&lt;/p&gt;
&lt;p&gt;The Libra paper states a difference between gas in Libra vs Ethereum: &lt;em&gt;&amp;ldquo;The
system is designed to have low fees during normal operations, when sufficient
capacity is available. This approach differs from some existing blockchains,
which target validators with lower capacity and thus at times have more demand
to process transactions than throughput. In these systems, fees spike during
periods of high demand &amp;ndash; representing a revenue source for the validators but
a cost for the users&amp;rdquo;&lt;/em&gt;&amp;hellip;this makes no sense to me. How are validators not
benefitting from high gas price?&lt;/p&gt;
&lt;p&gt;Libra transactions have side effects. This is the concept of &amp;ldquo;events&amp;rdquo; (Stellar
has the exact same thing, called &amp;ldquo;effects&amp;rdquo;). Transactions cannot read events.
In other words, transactions cannot take as input side effects of previous
transactions. The only supported mutation is explicit state mutation.&lt;/p&gt;
&lt;p&gt;In terms of protocol, applying a transaction is defined as:
&lt;code&gt;apply(state&lt;/code&gt;&lt;sub&gt;&lt;code&gt;i-1&lt;/code&gt;&lt;/sub&gt;&lt;code&gt;, transaction&lt;/code&gt;&lt;sub&gt;&lt;code&gt;i&lt;/code&gt;&lt;/sub&gt;&lt;code&gt;)&lt;/code&gt; yields
(&lt;code&gt;output&lt;/code&gt;&lt;sub&gt;&lt;code&gt;i&lt;/code&gt;&lt;/sub&gt;, &lt;code&gt;state&lt;/code&gt;&lt;sub&gt;&lt;code&gt;i&lt;/code&gt;&lt;/sub&gt;)&lt;/p&gt;
&lt;p&gt;Transactions are only a function of the current state. Because transactions are
deterministic, transactions/blocks can be replayed and auditing can be performed.&lt;/p&gt;
&lt;p&gt;A neat idea in this paper: to configure the genesis block and forks, special
transactions are added to the consensus protocol through configuration. They&amp;rsquo;re
not part of the ledger history. Essentially, configuration-as-vote.&lt;/p&gt;
&lt;h3 id=&#34;move&#34;&gt;Move&lt;/h3&gt;
&lt;p&gt;I&amp;rsquo;ve said above that transactions are implemented as smart contract calls. And
contracts are based on Move, a new programming language designed specifically
for Libra.&lt;/p&gt;
&lt;p&gt;Move source code compiles to Move IR (Intermediate Representation), which
compiles eventually to Move Bytecode. This is like Ethereum&amp;rsquo;s Solidity which
eventually gets compiled down to EVM (Ethereum Virtual Machine) instructions.&lt;/p&gt;
&lt;p&gt;Move &amp;ldquo;resources&amp;rdquo; are values (strings, integers, etc). Move modules are code to
interact with resources. Resources are hierarchical, stored under
&lt;code&gt;&amp;lt;account&amp;gt;/resources/&amp;lt;resource_account&amp;gt;.&amp;lt;resource_type&amp;gt;&lt;/code&gt; (e.g.
&lt;code&gt;0x12/resources/0x56.MyCurrency&lt;/code&gt;)&lt;/p&gt;
&lt;p&gt;Modules are code units published on Libra (equivalent to an Ethereum
constract). They declare structs and procedures. Structs contain data and/or
other structs. Procedures are functions. &lt;em&gt;&amp;ldquo;At a high level, the
module/struct/procedure relationship is similar to the class/object/method
relationship in object-oriented programming&amp;rdquo;&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;If you think this looks general-purpose you&amp;rsquo;d be right. But: &amp;ldquo;while move is
used to defined core system concepts, such as the Libra currency, users are
unable to publish custom modules that declare their own resource types&amp;rdquo;. In
other words: &lt;em&gt;there is no custom smart contract support!&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;ldquo;The key feature of Move is the ability to define custom resource types, which
have semantics inspired by linear logic&amp;rdquo;&lt;/em&gt;. What&amp;rsquo;s &amp;ldquo;linear logic&amp;rdquo;? You tell me,
&lt;a href=&#34;http://girard.perso.math.cnrs.fr/LLL.pdf&#34;&gt;here is the paper&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;ldquo;The Move type system provides special safety guarantees for resources. A
resource can never be copied, only moved&amp;rdquo;&lt;/em&gt;. Hence the name. Aha! More on the
design of move is &lt;a href=&#34;https://developers.libra.org/docs/assets/papers/libra-move-a-language-with-programmable-resources.pdf&#34;&gt;available here&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;storage&#34;&gt;Storage&lt;/h3&gt;
&lt;p&gt;For storage Libra uses Merkle trees. Nothing new here. History can be pruned by
validators. And validators &lt;em&gt;&amp;ldquo;are free to discard historical data not needed to
process new transactions&amp;rdquo;&lt;/em&gt;. In practice this could be a huge headache. Yes data
can be authenticated because it&amp;rsquo;s all part of an authenticated merkle tree. But
someone has to keep the whole history somewhere.&lt;/p&gt;
&lt;p&gt;The paper states: &lt;em&gt;&amp;ldquo;Clients can optionally create a replica of
the entire database by synchronizing the transaction history from the
validators. While creating a replica, a client can verify that validators
executed transactions correctly, which increases accountability and
transparency in the system&amp;rdquo;&lt;/em&gt;. This is true &lt;strong&gt;provided that validators keep track
of the entire history and open up their APIs&lt;/strong&gt;. Given that Libra is a
permissioned blockchain I doubt anonymous internet users would be able to
mirror the entire blochchain freely unless they&amp;rsquo;ve been following the network
since genesis. Validator nodes are likely to prune history after some time.
When this happens Libra&amp;rsquo;s full history might be in the hands of a happy few
(Facebook will certainly keep a copy if I had to guess!).&lt;/p&gt;
&lt;h3 id=&#34;consensus&#34;&gt;Consensus&lt;/h3&gt;
&lt;p&gt;Consensus in Libra is driven by &amp;ldquo;LibraBFT&amp;rdquo;, based on &lt;a href=&#34;https://arxiv.org/abs/1803.05069&#34;&gt;HotStuff&lt;/a&gt;. It
has the property to require 2 or more confirmations, and work with the concept
of blocks and &amp;ldquo;QC&amp;quot;s (Quorum Certificates). Nothing new under the sun.&lt;/p&gt;
&lt;h3 id=&#34;networking&#34;&gt;Networking&lt;/h3&gt;
&lt;p&gt;Networking is done with &lt;a href=&#34;https://libp2p.io/&#34;&gt;libp2p&lt;/a&gt;. Discovery/bootstrapping seems
unsolved: &lt;em&gt;&amp;ldquo;We currently assume clients have an out-of-band mechanism to find
the addresses of validators to submit transactions to &amp;ndash; the final version of
this mechanism is yet to be designed&amp;rdquo;&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&#34;if-libra-is-boring-why-fear-facebook&#34;&gt;If Libra is boring, why fear Facebook?&lt;/h2&gt;
&lt;p&gt;It should be pretty clear from the previous section that Libra brings
absolutely nothing new to the world of cryptocurrency. In some ways this is
good. It&amp;rsquo;ll probably be robust and safe to use because most of its components
have been battle-tested by others.&lt;/p&gt;
&lt;p&gt;Libra is &amp;ldquo;pseudonymous&amp;rdquo;. Accounts aren&amp;rsquo;t linked to anything by default. They&amp;rsquo;re
a formatted hash of a completely random public/private key pair. However, as
soon as Libra accounts are linked to real names and personal data, Libra stops
being anonymous and starts being worrisome.&lt;/p&gt;
&lt;p&gt;The same is true of Bitcoin or Ethereum today! If Facebook were to adopt them
as cryptocurrency, and users started paying each other through a wallet that
Facebook controls (existing Facebook apps, or the new &lt;a href=&#34;https://calibra.com/&#34;&gt;Calibra wallet&lt;/a&gt; app), they&amp;rsquo;ll
inevitably tie financial information to the existing mountain of data Facebook
already has about them.&lt;/p&gt;
&lt;p&gt;In short: don&amp;rsquo;t fear Libra. Fear Facebook.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Crypto Paper: Celo</title>
      <link>https://arnaudbrousseau.com/notes/crypto-paper-celo.html</link>
      <pubDate>Sat, 13 Apr 2019 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/crypto-paper-celo.html</guid>
      <description>&lt;p&gt;I read &lt;a href=&#34;https://arnaudbrousseau.com/pdfs/celo-whitepaper-draft-version-0.22.pdf&#34;&gt;Celo: A Multi-Asset Cryptographic Protocol for Decentralized Social
Payments&lt;/a&gt; (this link is a hosted version of what can be
found at &lt;a href=&#34;https://storage.googleapis.com/celo_whitepapers/Celo__A_Multi_Asset_Cryptographic_Protocol_for_Decentralized_Social_Payments.pdf&#34;&gt;this live URL&lt;/a&gt;, which points to version DRAFT
0.22 at the time of writing.)&lt;/p&gt;
&lt;p&gt;What did I learn? What did I understand? What was confusing? Is Celo worth something? Let&amp;rsquo;s write this down.&lt;/p&gt;
&lt;h2 id=&#34;new-concepts&#34;&gt;New Concepts&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s cover what I had to research while reading this whitepaper. Celo didn&amp;rsquo;t
invent these concepts but they are referenced or used.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Deflationary price instability&lt;/strong&gt;. Fancy term to say that prices denominated
in a currency tend to fall when the currency&amp;rsquo;s value goes up. For instance,
if goods were priced in ETH during the 2017 market boom, the prices
denominated in ETH would go down. This is the case for most (all?) cryptocurrencies&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ZK-SNARKs&lt;/strong&gt;. Stands for &amp;ldquo;Zero-Knowledge Succinct Non-Interactive Argument
of Knowledge&amp;rdquo;. A mathematical to prove the knowledge of a something (say, the
knowledge of which number hashes to &lt;code&gt;0x654737...&lt;/code&gt;) without revealing it to a
counter-party (in this example, you&amp;rsquo;d prove you know which number hashes to
&lt;code&gt;0x654737...&lt;/code&gt; without revealing the number). This is what
&lt;a href=&#34;https://z.cash/technology/zksnarks/&#34;&gt;ZCash&lt;/a&gt; uses. See &lt;a href=&#34;https://medium.com/@VitalikButerin/zk-snarks-under-the-hood-b33151a013f6&#34;&gt;this article&lt;/a&gt; by Vitalik
for an in-depth look.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Elastic supply rule&lt;/strong&gt;. Not entirely sure about that one to be honest. I
believe this refer&amp;rsquo;s to Celo&amp;rsquo;s &amp;ldquo;elastic&amp;rdquo; supply of Celo Dollars to make it
stable. When the demand grows more Celo Dollars are issued. When it
shrinks Celo Dollars are bought back.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;EigenTrust&lt;/strong&gt; (and PowerMethod). Algorithm to compute trust in a
peer-to-peer system. In the context of Celo this is used to make the network
feel more trustworthy. See &lt;a href=&#34;https://en.wikipedia.org/wiki/EigenTrust&#34;&gt;EigenTrust&lt;/a&gt;. The &amp;ldquo;Power
Method&amp;rdquo; is an implementation detail relevant to how eigenvectors (in the
context of EigenTrust) are computed. See &lt;a href=&#34;https://en.wikipedia.org/wiki/Power_iteration&#34;&gt;Power Iteration&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Proof-of-bonded-stake&lt;/strong&gt;: a small variation on &amp;ldquo;Proof of Stake&amp;rdquo;. In Celo the
participants&#39; weight is computed using the amount of Celo Gold bonded AND the
time left before each bond expires (the more time left for each bond, and the
more Celo Gold, the better)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CPI: Consumer Price Index&lt;/strong&gt;. A measure of the cost of various common goods
and services in a region or country.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Shelling-point scheme&lt;/strong&gt;. In Celo this is used to establish the fair price
of stable currencies. A &amp;ldquo;Schelling Point&amp;rdquo; is a &lt;a href=&#34;https://en.wikipedia.org/wiki/Focal_point_(game_theory)&#34;&gt;Focal
Point&lt;/a&gt;: a piece of data people agree upon without
communication. In this context Celo uses a &amp;ldquo;commit-then-reveal&amp;rdquo; scheme to
have voters agree on the price of stable coins. First, submit the hash of
your answer to the question &amp;ldquo;how much is COINX worth?&amp;rdquo;. Then, on the next
block, submit your answer. In order to get a reward your answer has to hash
what you committed on the previous block and be between some percentiles of
the right answer (say min. 25th, max. 75th). This incentivizes voters to give
an accurate answer.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A &amp;ldquo;run&amp;rdquo;&lt;/strong&gt;. Term for sell-pressure. When a lot of people want to get rid of
some asset (correlates with prices going down)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dash&amp;rsquo;s masternodes voting scheme&lt;/strong&gt;. See &lt;a href=&#34;https://docs.dash.org/en/stable/governance/understanding.html#budgets-and-masternode-voting&#34;&gt;Dash
docs&lt;/a&gt;. This is a type of governance to allocate
budgets to projects and developers in a decentralized way. Celo plans to use
this to fund technical improvements to the network, with a proposals and
&amp;ldquo;fee-for-implementation&amp;rdquo; on each of them, voted on by bonded stakeholders.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Futarchical governance&lt;/strong&gt;. To quote Wikipedia: futarchical governance is &amp;ldquo;a
form of government [&amp;hellip;] in which elected officials define measures of
national wellbeing, and prediction markets are used to determine which
policies will have the most positive effect&amp;rdquo;. This is cited by Celo as a
potential future improvement so that prediction markets as well as bonded
stakeholders can weigh in on currency or technical proposals. See
&lt;a href=&#34;https://en.wikipedia.org/wiki/Futarchy&#34;&gt;Futarchy&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Demurrage-charged currencies&lt;/strong&gt;. Demurrage is the cost of keeping a given
currency. In the case of standard earthling gold, you need a safe. A good
one. And maybe some cameras and gards if you have a lot of it. In the context
of Celo, demurrage is explored as a possibility to give people incentive to
keep regional currency flowing and avoid centralization. See
&lt;a href=&#34;https://en.wikipedia.org/wiki/Demurrage_(currency)&#34;&gt;Demurrage&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Natural-capital-backed currencies&lt;/strong&gt;. A mouthful to designate currencies
backed by something concrete/natural (gold, land, water, etc).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;celo-concepts&#34;&gt;Celo Concepts&lt;/h2&gt;
&lt;p&gt;Now let&amp;rsquo;s get into the meat of this paper: what is Celo? It&amp;rsquo;s a collection of
cryptocurrencies aimed at enabling social payments (think: &lt;a href=&#34;https://venmo.com/&#34;&gt;Venmo&lt;/a&gt;
or &lt;a href=&#34;https://transferwise.com&#34;&gt;TransferWise&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Celo doesn&amp;rsquo;t have any technical innovations at its core. The innovation is in
how the pieces are put together. To enable social payments Celo bets on
&lt;strong&gt;making public keys disappear&lt;/strong&gt; and have users issue payment to phone numbers,
emails, or other more familiar destination &amp;ldquo;addresses&amp;rdquo;. That&amp;rsquo;s done through a
simple distributed hash table of (alias, public key). To write a record
&lt;code&gt;(email@example.org, &#39;0x12345...&#39;)&lt;/code&gt; in the shared hash table, a validator has
to generate a secret and send it to &lt;a href=&#34;mailto:email@example.org&#34;&gt;email@example.org&lt;/a&gt;. This secret then has to
be signed with the private key associated with &lt;code&gt;0x12345...&lt;/code&gt; and sent back to
the validator. It&amp;rsquo;s not rocket-science but it sounds solid. I&amp;rsquo;d be happy not to
have to deal with public keys or QR codes to pay friends and family. This is
&lt;strong&gt;extremely similar&lt;/strong&gt; to &lt;a href=&#34;https://ens.domains/&#34;&gt;Ethereum Name Service&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Another &amp;ldquo;social&amp;rdquo; Celo feature is a distributed &amp;ldquo;trust&amp;rdquo; score based on previous
user payment activity. Neat but not exactly new or mind-boggling.&lt;/p&gt;
&lt;p&gt;The other interesting piece is the way Celo makes its currencies stable. Celo
Gold and a basket of other crypto-currencies (ETH, BTC, etc) are in the Celo
Reserve. This backs the Celo Dollar, which is a stable crypto-currency pegged
to USD. How is it kept stable? If the Celo Dollar goes above the US Dollar,
more Celo Dollars are created. If the Celo Dollar goes below: Celo dollars are
bought back with the Celo Reserve. The interesting bit comes from the fact that
the Celo Reserve is &lt;strong&gt;common to multiple stable currencies in Celo&lt;/strong&gt;. Say Celo
Dollar, Celo Euro and Celo Yen use the same underlying Celo reserve. If the
Celo Dollar is above its USD peg and the Celo Yen is below its JPY peg, the
reserve does not need to be touched. Celo Yens are bought back with brand-new
Celo Dollars. This shrinks the supply of Celo Yen and expands the Celo Dollar
without touching Celo&amp;rsquo;s reserve of Celo Gold and crypto-currencies.&lt;/p&gt;
&lt;p&gt;Celo also allows for new currencies to be created with their own reserve
(&amp;ldquo;partition reserve&amp;rdquo;) instead of using the common pre-established Celo reserve
of Celo Gold and other cryptos (&amp;ldquo;shared reserve&amp;rdquo;).&lt;/p&gt;
&lt;p&gt;Celo is a proof-of-stake network, with the variation that the weight of the
participant is proportional to the amount of money bonded AND the time left in
each bond. Each network participant can vote on the price of stable currencies
when they&amp;rsquo;re created and vote on network proposals which can be technical
improvements or new stable currencies. I personally really like the idea of the
network voting on technical proposals along with an implementation fee. Dash
does this as well.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>A Plan to Win your Next Interviewing Battle</title>
      <link>https://arnaudbrousseau.com/notes/plan-to-win-your-next-interviewing-battle.html</link>
      <pubDate>Mon, 11 Mar 2019 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/plan-to-win-your-next-interviewing-battle.html</guid>
      <description>&lt;p&gt;In October 2018 I quit my engineering job at Yelp. The 6.5 years I spent
working there were amazing in many ways but it was time for me to move on. The
purpose of this post is to reflect on my interviewing experience (all of it:
preparation phase, interviews, post-interview communication) and write down
details/tips. Hopefully it&amp;rsquo;s useful to somebody out there (you?) but if nothing
else it&amp;rsquo;ll surely be useful for me next time, when I&amp;rsquo;m on the job market again.&lt;/p&gt;
&lt;p&gt;Get cozy: this is a long read. Table of contents below:&lt;/p&gt;
&lt;!-- wow all the nbsps wow wow wow! Can you imagine how much fun I had?! --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#1-lead-generation&#34;&gt;1. Lead Generation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&#34;#1-1-build-your-resume&#34;&gt;1.1 Build your resume&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&#34;#1-2-job-applications&#34;&gt;1.2 Job applications&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&#34;#1-3-invest-in-your-network&#34;&gt;1.3 Invest in your network&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#2-interview-preparation&#34;&gt;2. Interview preparation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&#34;#2-1-hard-skills&#34;&gt;2.1 Hard Skills&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;    &lt;a href=&#34;#2-1-1-review-computer-science-fundamentals&#34;&gt;2.1.1 Review Computer Science Fundamentals&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;    &lt;a href=&#34;#2-1-2-pick-a-language-stick-with-it&#34;&gt;2.1.2 Pick a language &amp;amp; stick with it&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;    &lt;a href=&#34;#2-1-3-practice-improve-your-coding-skills&#34;&gt;2.1.3 Practice &amp;amp; improve your coding skills&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;    &lt;a href=&#34;#2-1-4-your-mistakes-are-your-best-assets&#34;&gt;2.1.4 Your mistakes are your best assets&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&#34;#2-2-don-t-forget-about-soft-skills&#34;&gt;2.2 Don&amp;rsquo;t forget about &amp;ldquo;soft&amp;rdquo; skills!&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;    &lt;a href=&#34;#2-2-1-questions-to-prepare-for&#34;&gt;2.2.1 Questions to prepare for&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;    &lt;a href=&#34;#2-2-2-tips-for-good-long-form-answers&#34;&gt;2.2.2 Tips for good long-form answers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;    &lt;a href=&#34;#2-2-3-craft-refine-your-story&#34;&gt;2.2.3 Craft &amp;amp; refine your story&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#3-interviewing-tips-and-tricks&#34;&gt;3. Interviewing tips and tricks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&#34;#3-1-the-interaction-log&#34;&gt;3.1 The interaction Log&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&#34;#3-2-planning&#34;&gt;3.2 Planning&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&#34;#3-3-tips-on-video-or-phone-interviews&#34;&gt;3.3 Tips on video or phone interviews&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&#34;#3-4-tips-on-on-site-interviews&#34;&gt;3.4 Tips on on-site interviews&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#4-interviews-are-over-now-what&#34;&gt;4. Interviews are over. Now what?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&#34;#4-1-making-the-most-out-of-your-recruiters&#34;&gt;4.1 Making the most out of your recruiters&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;    &lt;a href=&#34;#4-1-1-email-tips&#34;&gt;4.1.1 Email tips&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;    &lt;a href=&#34;#4-1-2-expectation-management&#34;&gt;4.1.2 Expectation management&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;    &lt;a href=&#34;#4-1-3-you-have-more-power-than-you-think&#34;&gt;4.1.3 You have more power than you think&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&#34;#4-2-offer-compensation-and-negotiation&#34;&gt;4.2 Offer, compensation and negotiation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&#34;#4-3-making-a-decision&#34;&gt;4.3 Making a decision&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;    &lt;a href=&#34;#4-3-1-evaluating-your-future-manager&#34;&gt;4.3.1 Evaluating your future manager&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;    &lt;a href=&#34;#4-3-2-interviewing-teammates&#34;&gt;4.3.2 Interviewing teammates&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;    &lt;a href=&#34;#4-3-3-gauging-work-culture&#34;&gt;4.3.3 Gauging work culture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&#34;#4-4-reflection-on-interviewing-pipelines-and-processes&#34;&gt;4.4 Reflection on interviewing pipelines and processes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;    &lt;a href=&#34;#4-4-1-automatically-graded-coding-test&#34;&gt;4.4.1 Automatically graded coding test&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;    &lt;a href=&#34;#4-4-2-realistic-interviews&#34;&gt;4.4.2 Realistic interviews&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;    &lt;a href=&#34;#4-4-3-no-surprises-interviews&#34;&gt;4.4.3 No-surprises interviews&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#5-a-final-offering-my-personal-todo-list&#34;&gt;5. A final offering: my personal TODO list&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;1-lead-generation&#34;&gt;1. Lead Generation&lt;/h1&gt;
&lt;p&gt;First things first let&amp;rsquo;s talk about how to get an interview. Three main parts:
your resume, your network, and other people&amp;rsquo;s networks.&lt;/p&gt;
&lt;h2 id=&#34;11-build-your-resume&#34;&gt;1.1. Build your resume&lt;/h2&gt;
&lt;p&gt;There are a lot of strong opinions out there about what should and shouldn&amp;rsquo;t go
into a resume. My experience, both as someone who screened hundreds of
resumes and as someone who applied to tens of job postings, is that &lt;strong&gt;resumes
are at best neutral&lt;/strong&gt;. If you have an awful resume, you probably won&amp;rsquo;t get
responses when applying. If you fix your resume, you&amp;rsquo;ll probably get responses
and that&amp;rsquo;s the sweet spot. If you build an amazing resume, you&amp;rsquo;ll also get
responses, but it won&amp;rsquo;t help you in any other way.&lt;/p&gt;
&lt;p&gt;To be effective with your time, do not spend too much time on perfecting your
resume. Give it the attention it deserves and move on quickly. It&amp;rsquo;s much better
to spend your time on generating leads, finding referrals, or brushing up on your
CS fundamentals (more on that later).&lt;/p&gt;
&lt;p&gt;That being said, here are the cardinal resume sins in my book:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Proprietary formats&lt;/strong&gt;: not everyone has Microsoft Word installed! Stick to PDF.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Grammar or spelling mistakes&lt;/strong&gt;: Given the small number of words on a resume,
seeing a grammar or spelling mistake is a huge red flag.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pretentious labels&lt;/strong&gt;: &amp;ldquo;ninja&amp;rdquo;, &amp;ldquo;hardcore&amp;rdquo;, &amp;ldquo;guru&amp;rdquo; are an immediate turn-off&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dead links&lt;/strong&gt;: if it&amp;rsquo;s on your resume, it should work!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Some other tips:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Keep it short!&lt;/strong&gt; People reading resumes have a limited amount of time
(typically 30 seconds to 1 minute per resume)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Check your online presence&lt;/strong&gt; (Google yourself!). Time to freshen up your
personal site if you have one, make sure to dust off old-looking things in
your public Twitter, cleanup your Github, etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For reference and transparency, here&amp;rsquo;s &lt;a href=&#34;https://arnaudbrousseau.com/labs/resume&#34;&gt;my resume&lt;/a&gt;. Feel free to
open a pull request &lt;a href=&#34;https://github.com/ArnaudBrousseau/arnaudbrousseau.com/blob/master/src/files/labs/resume/index.html&#34;&gt;on
Github&lt;/a&gt;
if you spot something off ;)&lt;/p&gt;
&lt;h2 id=&#34;12-job-applications&#34;&gt;1.2. Job applications&lt;/h2&gt;
&lt;p&gt;Once you have a resume and a web presence it&amp;rsquo;s time to actually apply for jobs!
As a software engineer you have a ton of options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Passive recruiter outreach: we&amp;rsquo;ve all received cold emails from technical
&amp;ldquo;sourcers&amp;rdquo; (recruiters). They feels like spam. Most of the time they are.
Regardless, I save the interesting ones into a folder. When my job search
started I reached back out and I got interesting leads/contacts from this.&lt;/li&gt;
&lt;li&gt;Referrals: by far the most effective lead-generation tool if you&amp;rsquo;re
already working as an engineer. Hit up your friend list on Facebook or lookup
people on social media (Twitter, LinkedIn).  Most of the time companies have
referral programs in place: if you get the job, the person referring you gets
a cash reward. By referring you they&amp;rsquo;re doing you a favor, but you&amp;rsquo;re
potentially doing them a favor if you land the job! Win-win.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://triplebyte.com/iv/Vzk8gi2/cp&#34;&gt;TripleByte&lt;/a&gt; (this is my own referral
link.  Here is a &lt;a href=&#34;https://triplebyte.com&#34;&gt;link without affiliation&lt;/a&gt; if you
prefer): I&amp;rsquo;ve used their service successfully and can&amp;rsquo;t recommend it enough.
If you&amp;rsquo;re accepted in their program you&amp;rsquo;ll get to go directly on-site with
companies interested in your profile. That&amp;rsquo;s a huge potential time saving! If
you don&amp;rsquo;t get accepted it&amp;rsquo;s still good practice to go through TripleByte&amp;rsquo;s
interviews.  Treat it like training. It&amp;rsquo;s 100% free to apply.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://underdog.io/&#34;&gt;Underdog.io&lt;/a&gt;: geared towards finding small startups. I
personally haven&amp;rsquo;t had much success with this but the service seems high
quality with quite a lot of startups to choose from.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://hired.com/&#34;&gt;Hired&lt;/a&gt;: surprisingly effective for me. Maybe that was
luck? Many companies reached out. High-quality interviews came from this platform.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;13-invest-in-your-network&#34;&gt;1.3. Invest in your network&lt;/h2&gt;
&lt;p&gt;It should be clear from the list above: your professional network is going to
be a strong asset when looking for a job. A &amp;ldquo;professional network&amp;rdquo; doesn&amp;rsquo;t have
to mean colleagues in the strict sense. Think wider.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For students: think professors, TAs, classmates.&lt;/li&gt;
&lt;li&gt;For engineers at small startups: think contractors, support people from
vendors, people you&amp;rsquo;ve met at conferences or meetups.&lt;/li&gt;
&lt;li&gt;For engineers at bigger companies: all of the above plus your colleagues if
you&amp;rsquo;re comfortable opening up about looking for new opportunities.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&amp;rsquo;ve gotten my first internship at Google thanks to a well-connected professor
of mine. The timing worked out. Yes I got lucky. What I want you to consider:
please take more chances. Go talk to people around you even when you think the
odds aren&amp;rsquo;t in your favor. You only need one of these to work out to make it
worth your while!&lt;/p&gt;
&lt;h1 id=&#34;2-interview-preparation&#34;&gt;2. Interview preparation&lt;/h1&gt;
&lt;p&gt;In this section we&amp;rsquo;re going over what&amp;rsquo;s most important: preparation before your
&lt;del&gt;battle&lt;/del&gt;interview.&lt;/p&gt;
&lt;h2 id=&#34;21-hard-skills&#34;&gt;2.1. Hard Skills&lt;/h2&gt;
&lt;h3 id=&#34;211-review-computer-science-fundamentals&#34;&gt;2.1.1. Review Computer Science Fundamentals&lt;/h3&gt;
&lt;p&gt;I&amp;rsquo;ve written about this &lt;a href=&#34;https://arnaudbrousseau.com/notes/tech-interviews.html&#34;&gt;previously&lt;/a&gt;: I really
don&amp;rsquo;t know why Computer Science Fundamentals are such a big focus in our
industry. The reality of interviewing is that they are the most common
denominator across companies, roles, and level of experience. Love it or hate it,
studying CS fundamentals is the most efficient thing you can do if you
are prepping for technical interviews because 1) it&amp;rsquo;s probably been a while
since you&amp;rsquo;ve done anything with binary trees or linked lists and 2) these
questions come up &lt;em&gt;all the time&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;So what exactly is considered &amp;ldquo;CS fundamentals&amp;rdquo;? Here&amp;rsquo;s my take on it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Big-O analysis&lt;/li&gt;
&lt;li&gt;Hashmaps: implementation (be able to implement this data structure from scratch in your language of choice), runtime (know the main operations and their big-o complexity)&lt;/li&gt;
&lt;li&gt;Dynamic Arrays: implementation, runtime&lt;/li&gt;
&lt;li&gt;Linked List: implementation, runtime&lt;/li&gt;
&lt;li&gt;(Binary Search) Trees: implementation, runtime, algorithms to traverse them
(BFS, DFS)&lt;/li&gt;
&lt;li&gt;Sorting Algorithms: quicksort, bubble sort, insertion sort, heapsort.  What to
study: implementation, runtime, worst case, best case. Bonus: know  which
type of inputs performs best/worst on each of the different sorting
algorithms.&lt;/li&gt;
&lt;li&gt;Graphs: representations in memory and basic algorithms for traversal (BFS,
DFS should be a no-brainer to code!)&lt;/li&gt;
&lt;li&gt;(Bonus) Tries, Bloom Filters: no need to know the implementation. Look into
their runtime and main advantages/trade-offs.&lt;/li&gt;
&lt;li&gt;(Bonus) Dijkstra and/or A* since it tends to underpin a lot of coding
questions about graphs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;212-pick-a-language-amp-stick-with-it&#34;&gt;2.1.2. Pick a language &amp;amp; stick with it&lt;/h3&gt;
&lt;p&gt;&amp;ldquo;Coding interviews are basically glorified IQ tests&amp;rdquo;. That&amp;rsquo;s something I&amp;rsquo;ve
heard directly from an interviewer. I think it&amp;rsquo;s an accurate statement.&lt;/p&gt;
&lt;p&gt;The good news is that no IQ test is perfect and you can &amp;ldquo;game&amp;rdquo; the system
provided that you know what&amp;rsquo;s expected of you. What it comes down to is: &lt;strong&gt;save
as much brain power as possible&lt;/strong&gt;. The more resources you have to think about
the problem itself the more likely you are to succeed in interviews.&lt;/p&gt;
&lt;p&gt;Picking a language that you&amp;rsquo;re fluent in saves you a lot of mental energy.
Instead of thinking about the best way (or how) to write a class, or trying to
avoid off-by-one errors, practice ahead of time so that a high percentage of
your time is allocated to thinking about the problem during an actual
interview.&lt;/p&gt;
&lt;p&gt;Here is a non-exhaustive list of things to practice applicable to Python (my
interviewing language of choice). If you pick another language the specifics
between parenthesis vary but the concepts remain the same:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Basic &amp;ldquo;closed&amp;rdquo; loops&lt;/strong&gt; (&lt;code&gt;for i in range(begin, end)&lt;/code&gt;). Make sure you won&amp;rsquo;t get surprised by &lt;code&gt;range&lt;/code&gt;&amp;rsquo;s behavior. &lt;code&gt;begin&lt;/code&gt; is &lt;strong&gt;inclusive&lt;/strong&gt;, &lt;code&gt;end&lt;/code&gt; is &lt;strong&gt;exclusive&lt;/strong&gt; so to loop through with i taking values 1, 2, and 3: &lt;code&gt;for i in range(1, 4)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Backward loops&lt;/strong&gt; (&lt;code&gt;for i in range(end-1, begin-1, -1)&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&amp;ldquo;open&amp;rdquo; loops&lt;/strong&gt; (&lt;code&gt;while some_condition&lt;/code&gt;). Make sure you know how to terminate loops with &lt;code&gt;break&lt;/code&gt;. Make sure you&amp;rsquo;re familiar with &lt;code&gt;continue&lt;/code&gt; and its behavior&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Class syntax&lt;/strong&gt; (class declaration, &lt;code&gt;__init__&lt;/code&gt;, magic methods, inheritance)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Code execution&lt;/strong&gt; (memorize &lt;code&gt;if __name__ == &amp;quot;__main__&amp;quot;&lt;/code&gt; for instance)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Assertions&lt;/strong&gt; (use &lt;code&gt;assert&lt;/code&gt; and use assertion messages!)&lt;/li&gt;
&lt;li&gt;(Python specific) List comprehensions: don&amp;rsquo;t &lt;em&gt;over&lt;/em&gt;use them, but definitely
know how they work and where to use them (typically when you want to do
complex destructuring or filtering). They can save a ton of time&lt;/li&gt;
&lt;li&gt;(Python specific) Pro-tip: building dicts programatically! This can be done
with list comprehension: &lt;code&gt;d = dict([(k, v) for k, v in ... if ...]&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;(Python specific) Pro-tip: use &lt;code&gt;defaultdict&lt;/code&gt;! This will avoid if statements to
handle cases where keys aren&amp;rsquo;t initialized (useful in the case when you want
to count things or compute averages, frequencies per key, etc)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;213-practice-amp-improve-your-coding-skills&#34;&gt;2.1.3. Practice &amp;amp; improve your coding skills&lt;/h3&gt;
&lt;p&gt;You&amp;rsquo;ll be judged on more than just pure &amp;ldquo;coding&amp;rdquo; during a coding interview.
Whether they&amp;rsquo;re aware of it or not, interviewers will grade you based on:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How quickly you spot mistakes on your own&lt;/li&gt;
&lt;li&gt;How quickly/accurately you can react to a hint when given one&lt;/li&gt;
&lt;li&gt;How well-spoken you are and how well you understand what they&amp;rsquo;re
saying (yup, native English speakers have a huge advantage here!)&lt;/li&gt;
&lt;li&gt;How neat your handwriting is and how well you manage the space on the
whiteboard. Or if the interviewer is okay with a laptop: how fast you type,
how familiar you are with the editor you use&lt;/li&gt;
&lt;li&gt;How positive you are (are you smiling? Friendly?)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Because there are so many things you&amp;rsquo;ll be judged on aside from coding, don&amp;rsquo;t
fall into the trap of practicing on too many different problems. What I suggest
instead: pick a problem and try to solve it in &lt;em&gt;different settings&lt;/em&gt;, ideally a
few days apart.&lt;/p&gt;
&lt;p&gt;First practice it in the most comfortable setting: with your favorite
IDE/editor. This forces you to focus on the problem itself. Then practice
solving the same problem on a Google doc (or somewhere with no syntax
highlighting). This forces you to focus on language constructs and syntax that
you might be unfamiliar with. Copy/paste the code you wrote into your editor/IDE
only once you&amp;rsquo;re damn sure it compiles/run. It probably won&amp;rsquo;t and that&amp;rsquo;s fine!
Make a note of the mistakes (more on this in the following section)
and come back to your Google doc to re-examine your code. Do this until your
code runs! Then solve the same problem on paper or a whiteboard to
practice handwriting and space management.&lt;/p&gt;
&lt;p&gt;Finally, if you&amp;rsquo;re interviewing with a company which does whiteboard coding
only (Google, Facebook, Amazon, probably others &amp;ndash; unfortunately!) try solving
a few problems on the whiteboard first while talking out loud as if a person
was listening and judging. And time yourself. Afterwards, copy what you wrote
on paper or whiteboard and type it in mindlessly in an editor/IDE. Does it
compile/run? Does it do what you want? Make note of the mistakes and repeat.
Speaking of mistakes&amp;hellip;&lt;/p&gt;
&lt;h3 id=&#34;214-your-mistakes-are-your-best-assets&#34;&gt;2.1.4. Your mistakes are your best assets&lt;/h3&gt;
&lt;p&gt;Something worth buying: a nice notebook and a pen that you like. It&amp;rsquo;s not that
expensive and it should help you a ton. This notebook should be your &amp;ldquo;mistake&amp;rdquo;
log. Every time you screw up (you expected your recursion to finish but it
doesn&amp;rsquo;t, you made a silly syntax error, maybe your loop was off by one), log that
into the notebook and move on.&lt;/p&gt;
&lt;p&gt;Over time more mistakes will pile on. Regularly review the contents of your
notebook to spot trends: are you making many syntax errors? Do you always
forget to declare variables when they&amp;rsquo;re in a &lt;code&gt;for&lt;/code&gt; loop? What sort of problems
are causing you the most grief?&lt;/p&gt;
&lt;p&gt;I reviewed my notebook once a week and before each interview. This helped me
tremendously. Why? Awareness is more than half the battle. There are hundreds of
potential mistakes people make when coding but you have your own special
weaknesses.&lt;/p&gt;
&lt;p&gt;Being aware and actively on the lookout for &lt;strong&gt;specific&lt;/strong&gt; types of mistakes
drastically reduces the chance of making them. With a bit of training you&amp;rsquo;ll
spot them as soon as they&amp;rsquo;re on your computer screen or whiteboard. Eventually
you&amp;rsquo;ll probably eliminate them &lt;em&gt;in your mind&lt;/em&gt;, which means entire classes of
mistakes/bugs are gone!&lt;/p&gt;
&lt;h2 id=&#34;22-dont-forget-about-soft-skills&#34;&gt;2.2. Don&amp;rsquo;t forget about &amp;ldquo;soft&amp;rdquo; skills!&lt;/h2&gt;
&lt;p&gt;This was prompted by my preparation for Amazon&amp;rsquo;s and Facebook&amp;rsquo;s interview
processes. Soft skills are really important. Most candidates underestimate the
importance of soft skills in coding interviews and do not prepare effectively as
a result. That&amp;rsquo;s good news for you: preparing &lt;em&gt;just a little bit&lt;/em&gt; puts you
ahead of the pack. It&amp;rsquo;s definitely worth investing an afternoon or two don&amp;rsquo;t you
think?&lt;/p&gt;
&lt;h3 id=&#34;221-questions-to-prepare-for&#34;&gt;2.2.1. Questions to prepare for&lt;/h3&gt;
&lt;p&gt;Here&amp;rsquo;s a list of questions/prompts to prepare. I gathered this list as I went
through interviews. Being prepared for those will get you 95% of the way there
and you probably won&amp;rsquo;t feel surprised by any &amp;ldquo;soft&amp;rdquo; questions anymore:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What brings you here? (most common soft question by far)&lt;/li&gt;
&lt;li&gt;So what don&amp;rsquo;t you tell me about yourself? (probably second most common!)&lt;/li&gt;
&lt;li&gt;Tell me about a time when you were faced with a problem that had a number of possible solutions. What was the problem and how did you determine the course of action? What was the outcome of that choice?&lt;/li&gt;
&lt;li&gt;When did you take a risk, make a mistake, or fail? How did you respond and
how did you grow from that experience?&lt;/li&gt;
&lt;li&gt;Describe a time you took the lead on a project.&lt;/li&gt;
&lt;li&gt;What did you do when you needed to motivate a group of individuals or promote collaboration on a particular project?&lt;/li&gt;
&lt;li&gt;How have you leveraged data to develop a strategy?&lt;/li&gt;
&lt;li&gt;What were some of the best things you&amp;rsquo;ve built?&lt;/li&gt;
&lt;li&gt;What are you proud of?&lt;/li&gt;
&lt;li&gt;What could you have done better?&lt;/li&gt;
&lt;li&gt;What were some excellent collaborations you&amp;rsquo;ve had?&lt;/li&gt;
&lt;li&gt;Tell me about a time when you advocated for and pushed your own ideas
forward despite opposition?&lt;/li&gt;
&lt;li&gt;How do you deal with conflict?&lt;/li&gt;
&lt;li&gt;How do you like to give and receive feedback?&lt;/li&gt;
&lt;li&gt;Tell me about a time when you had to complete something in a limited amount of time of with a limited amount of resources&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Finally, prepare a big list of questions for non-technical folks and technical
folks. You should have enough questions to last a whole lunch break with
either type of people (I&amp;rsquo;ve found that 10 questions is generally more than
enough).&lt;/p&gt;
&lt;h3 id=&#34;222-tips-for-good-long-form-answers&#34;&gt;2.2.2. Tips for good long-form answers&lt;/h3&gt;
&lt;p&gt;These tips (in italic) are taken straight from Amazon&amp;rsquo;s &amp;ldquo;in person&amp;rdquo; interview preparation guide that you can find &lt;a href=&#34;https://www.amazon.jobs/en/landing_pages/in-person-interview&#34;&gt;here&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&amp;ldquo;&lt;em&gt;Ensure each answer has a beginning, middle, and end. Describe the
situation or problem, the actions you took, and the outcome&lt;/em&gt;&amp;rdquo;. More
specifically for engineering stories I&amp;rsquo;ve found that it works best to go
top-down. Start by explaining the broad context of your work, what you were
tasked with, then dig into the problem you want to discuss.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;&lt;em&gt;Prepare short descriptions of a handful of different situations and be
ready to answer follow-up questions with greater detail. Select examples
that highlight your unique skills&lt;/em&gt;&amp;rdquo;. That&amp;rsquo;s gold. It&amp;rsquo;s basically saying:
chop it up! Don&amp;rsquo;t spill your whole story at once. Being able to deliver it
piece-by-piece is going to help you in behavioral interviews because small
pieces are generally composable and reusable.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;&lt;em&gt;Have specific examples that showcase your experience, and demonstrate that
you&amp;rsquo;ve taken risks, succeeded, failed, and grown in the process&lt;/em&gt;&amp;rdquo;. That&amp;rsquo;s
just another way of saying that what happens doesn&amp;rsquo;t matter. Usually in
behavioral interviews the interviewer is interested in how you choose to
react to situations and what you learn from them. So instead of stopping at
&amp;ldquo;we disagreed on how to use Jira&amp;rdquo;, talk about what task management meant to
you, how disagreeing led you to reconsider your position on what that meant
at the time and what it means to you now (assuming that disagreeing on Jira
processes triggered that line of thought. Don&amp;rsquo;t ever lie! Interviewers have
a pretty strong bullshit detector)&lt;/li&gt;
&lt;li&gt;&amp;ldquo;&lt;em&gt;Specifics are key; avoid generalizations. Give a detailed account of one
situation for each question you answer, and use data or metrics to support
your example&lt;/em&gt;&amp;rdquo;. That&amp;rsquo;s also extremely important. Don&amp;rsquo;t beat around the bush
by being generic. You may be in a behavioral interview but you&amp;rsquo;re an
engineer still! Your interviewer will ask you for specifics if you don&amp;rsquo;t
provide them in your first answer.  Your time is limited so it&amp;rsquo;s best to
give those ahead of time.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;&lt;em&gt;Be forthcoming and straightforward. Don&amp;rsquo;t embellish or omit parts of the
story&lt;/em&gt;&amp;rdquo;. Yup. Don&amp;rsquo;t lie please.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;223-craft-amp-refine-your-story&#34;&gt;2.2.3. Craft &amp;amp; refine your story&lt;/h3&gt;
&lt;p&gt;This has already been mentioned in the previous section but it&amp;rsquo;s worth calling
out on its own: you should have an answer to the dreaded, classic questions:
&amp;ldquo;What brings you here?&amp;rdquo; and &amp;ldquo;So why don&amp;rsquo;t you tell me about yourself?&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;This deserves special attention. Look at yourself in the mirror, ask a friend
to tell you what they think, and perfect your answers until you feel confident.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;re transitioning from one role to another (say backend to iOS
development, or from marketing analytics to engineering), it&amp;rsquo;s worth crafting a
compelling story and be ready to answer &amp;ldquo;so why did you choose to switch from X
to Y?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Important note: crafting a story is different from lying. Don&amp;rsquo;t say things that
aren&amp;rsquo;t true. Don&amp;rsquo;t try to embellish what happened. Do think about where you&amp;rsquo;re
going to start, what you want to convey, and how: what do you want the listener
to take away from your answer to these question?&lt;/p&gt;
&lt;h1 id=&#34;3-interviewing-tips-and-tricks&#34;&gt;3. Interviewing tips and tricks&lt;/h1&gt;
&lt;h2 id=&#34;31-the-interaction-log&#34;&gt;3.1. The interaction Log&lt;/h2&gt;
&lt;p&gt;I kept a log of all the communications I had with every company, regardless of
the stage. Here&amp;rsquo;s an exerpt for a company didn&amp;rsquo;t move forward with:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/interaction-log.png&#34; alt=&#34;Interaction Log Excerpt&#34;&gt;&lt;/p&gt;
&lt;p&gt;I had to redact a lot of it, but the general structure holds. Some things worth
pointing out:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&amp;ldquo;priority&amp;rdquo; maps to how badly I wanted that job:
&lt;ul&gt;
&lt;li&gt;P0: I’d take a pay cut to work there&lt;/li&gt;
&lt;li&gt;P1: Given a good offer and a decent team I’d work there&lt;/li&gt;
&lt;li&gt;P2: Given an excellent offer and the right team, I’d work there&lt;/li&gt;
&lt;li&gt;P3: Good for training/exploration only, would never accept an offer unless it’s truly exceptional&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;As you can see I had this in a Google Doc to be able to access it from
anywhere (esp.  from my phone &amp;ndash; this came in handy more than once!), and
color-coded by priority.&lt;/li&gt;
&lt;li&gt;Putting random TODOs in there is also useful&lt;/li&gt;
&lt;li&gt;I initially started with a spreadsheet but I found that freeform text worked
best to jot down quick thoughts during a call (that document was my main
medium to take notes during recruiter calls)&lt;/li&gt;
&lt;li&gt;It&amp;rsquo;s important to log the date!&lt;/li&gt;
&lt;li&gt;Write down as much as you can write after the call, interview or interaction
happens.&lt;/li&gt;
&lt;li&gt;Treat this as an append-only log. Don&amp;rsquo;t erase anything! This will come in
handy later on when you&amp;rsquo;re trying to make a decision, and will keep you
honest&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;32-planning&#34;&gt;3.2. Planning&lt;/h2&gt;
&lt;p&gt;Planning is one of the most crucial aspects of a job hunt. Put everything in one
calendar (I used Google Calendar) and be very diligent about keeping track of
who is supposed to call you when. Set reminders to prepare for the call, and take
notes!&lt;/p&gt;
&lt;p&gt;Another tip that I can give here: try your best to line up interviews that you
care about least first, and the ones that you care about most last.&lt;/p&gt;
&lt;h2 id=&#34;33-tips-on-video-or-phone-interviews&#34;&gt;3.3. Tips on video or phone interviews&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Get familiar with &lt;a href=&#34;https://coderpad.io/&#34;&gt;Coderpad&lt;/a&gt;, play with the interface.
Python pro-tip: you can drop a debugging statement, it&amp;rsquo;ll work just fine
(&lt;code&gt;import pdb; pdb.set_trace();&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Don&amp;rsquo;t use the built-in microphone from your laptop. Get a headset! If you
have one already great. Otherwise, pick a cheap one from Amazon. This helps
your interviewer hear you better and this helps you hear your interview
better. Win-win.&lt;/li&gt;
&lt;li&gt;Get a blank paper sheet and a pen near you to write things down. If the
interviewer hears you typing they&amp;rsquo;ll think you&amp;rsquo;re cheating.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;34-tips-on-on-site-interviews&#34;&gt;3.4. Tips on on-site interviews&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Aim to be 15 minutes early. Most of the time you&amp;rsquo;ll actually be early. That&amp;rsquo;s
a perfect opportunity to skim your &amp;ldquo;mistakes log&amp;rdquo; one more time before
starting your interview day and get in the mindset.&lt;/li&gt;
&lt;li&gt;Print your resume, just in case. Even in this day and age it came in handy
a couple of times to have a printed copy of my resume ready to show.&lt;/li&gt;
&lt;li&gt;If lunch is provided: eat light! There&amp;rsquo;s a dip in energy when digestion kicks
in. Eating light helps with this.&lt;/li&gt;
&lt;li&gt;In a similar spirit: try to limit your sugar/caffeine intake to a minimum to
prevent acute spikes/dips of energy.&lt;/li&gt;
&lt;li&gt;After a full round of on-site interviews it&amp;rsquo;s really tempting to relax.
Instead force yourself to write down notes about what happened. What were the
names of your interviewers? What were their positions/teams? Would you like
to work with them on a daily basis? Which questions did they ask? How do you
think you did?  What did you think of the culture overall? This is your
chance to be honest and record your unbiased opinion. Your future self will
thank you. When offers are on the table it helps to have a written record
to eliminate bias.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;4-interviews-are-over-now-what&#34;&gt;4. Interviews are over. Now what?&lt;/h1&gt;
&lt;p&gt;So you&amp;rsquo;ve gone through your interviews and hopefully have gotten far enough in
the process that you&amp;rsquo;re stressed and unsure about what to do next. Negotiating
your salary and committing to a decision is no easy task. Below I&amp;rsquo;m laying out
my experience with both of these. I&amp;rsquo;m offering some of my personal criteria to
evaluate each company and some tips about offer negotiation. Ready?&lt;/p&gt;
&lt;h2 id=&#34;41-making-the-most-out-of-your-recruiters&#34;&gt;4.1. Making the most out of your recruiters&lt;/h2&gt;
&lt;h3 id=&#34;411-email-tips&#34;&gt;4.1.1. Email tips&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Generally, be as concise as possible. Stay to-the-point while staying cordial.&lt;/li&gt;
&lt;li&gt;Be aware that your recruiter is juggling between multiple candidates. Keep
your emails short and precise. Instead of saying &amp;ldquo;When are you free to chat
this week? I&amp;rsquo;m free Monday or Tuesday&amp;rdquo;, say &amp;ldquo;I&amp;rsquo;m free to talk this week on
Monday from 12pm to 2pm or on Tuesday from 2pm to 5pm (all times PT). Would
this work on your end?&amp;rdquo;. This saves one email round-trip.&lt;/li&gt;
&lt;li&gt;State time zones. Always.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;412-expectation-management&#34;&gt;4.1.2. Expectation management&lt;/h3&gt;
&lt;p&gt;Be as transparent as you can about your timeline from the beginning. In my
experience there isn&amp;rsquo;t much benefit to information asymmetry. Recruiters are
your best allies: the more they know about your particular set of needs, the
better off you&amp;rsquo;ll be. Why are they allies? They usually have financial incentive
to meet hiring targets. You get in the door, they get paid, both of you are
happy!&lt;/p&gt;
&lt;p&gt;Along the same lines: be very diligent about informing your recruiter(s) about
changes along the way.
I found that having a list of names/emails for each company helped immensely
(you don&amp;rsquo;t have to think hard about who to email when something changes if you
have one place where everything is). I kept track of this as part of
my big &amp;ldquo;interaction log&amp;rdquo; document (described &lt;a href=&#34;#3-1-the-interaction-log&#34;&gt;above&lt;/a&gt;).&lt;/p&gt;
&lt;h3 id=&#34;413-you-have-more-power-than-you-think&#34;&gt;4.1.3. You have more power than you think&lt;/h3&gt;
&lt;p&gt;You have a lot of power as an engineer looking for a new job. The market right
now (2018-2019) is as good as it gets. Don&amp;rsquo;t be a jerk about it (obviously!) but
be aware that you can ask for a lot. Asking nicely will get you most of what you
want, so remember to ask! This is especially important when it comes to&amp;hellip;&lt;/p&gt;
&lt;h2 id=&#34;42-offer-compensation-and-negotiation&#34;&gt;4.2. Offer, compensation, and negotiation&lt;/h2&gt;
&lt;p&gt;A couple of links on the subject of negotiation:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.kalzumeus.com/2012/01/23/salary-negotiation/&#34;&gt;Salary Negotiation&lt;/a&gt; (online article)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.amazon.com/Fearless-Salary-Negotiation-step-step/dp/0692568689/&#34;&gt;Fearless salary negotiations&lt;/a&gt; (book)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The above resources will do a far better job than I can at teaching you about
salary negotiation. A few things I&amp;rsquo;d like to stress:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;From personal experience: &amp;ldquo;never be the first to give a number&amp;rdquo; doesn&amp;rsquo;t work
well. I found that asking for an aggressive target works better. The best
thing you can do is ask a few people who work at the company for compensation
ranges and shoot slightly above.&lt;/li&gt;
&lt;li&gt;About competing offers: their importance really depends on companies. Some
will budge quite a bit if you tell them you have competing offers. Some only
budge if the offer is from a big name such as Facebook or Google. And some
don&amp;rsquo;t respond at all. So I wouldn&amp;rsquo;t attach too much importance to competing
offers. It&amp;rsquo;s way more important to crush your interviews and ask for the
right compensation.&lt;/li&gt;
&lt;li&gt;Remember: your recruiter is your side! They may have an incentive to make
you sign with the minimum salary possible, but at the end of the day what
matters to them most is that you sign at all!&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;43-making-a-decision&#34;&gt;4.3. Making a decision&lt;/h2&gt;
&lt;p&gt;There&amp;rsquo;s a ton of criteria to evaluate when picking a job. It can get emotional
and overwhelming so I&amp;rsquo;ve used &lt;a href=&#34;https://docs.google.com/spreadsheets/d/1C8T8lO-OBhN9jMHz8q_2XNYIAyJkVteJghIdJXZajag/edit?usp=sharing&#34;&gt;this
spreadsheet&lt;/a&gt;
to be as rational as possible. Columns are criteria you care about
(compensation, quality of manager, technical stack, etc). Each of them is of a
certain importance to you and that&amp;rsquo;s reflected by a weight (from 1 to
infinity). Rows are companies you&amp;rsquo;re considering, and each company gets a 0-10
score for each column. The rightmost column displays a weighted sum to help you
compare easily and see which company comes at the top.&lt;/p&gt;
&lt;p&gt;What should you care about even? What should the weights be set to? Well that&amp;rsquo;s
personal. But here&amp;rsquo;s my opinion: a job is mostly made of &lt;strong&gt;people&lt;/strong&gt;. Your
manager and teammates are crucial. You&amp;rsquo;re going to spend 40hrs+ per week
interacting with them. Make sure you consider this &lt;em&gt;very&lt;/em&gt; carefully. A great
compensation and a kick-ass brand won&amp;rsquo;t save you from a lousy manager or a
toxic team. So weight this accordingly.&lt;/p&gt;
&lt;p&gt;Another piece of advice that I&amp;rsquo;ve heard from mentors and colleagues:
focus on learning and growth early in your career. Weight compensation lightly
if that&amp;rsquo;s possible for you to do.&lt;/p&gt;
&lt;p&gt;Now how do you actually go about evaluating your future company,
manager, or teammates during your interviews? Obviously it depends. Teammates,
managers and engineering cultures are all made of people. A manager who feel
awful to me might be a great fit for you. Below are my &lt;strong&gt;personal&lt;/strong&gt; criteria to
gauge these things. I encourage you to develop your own and write them down.&lt;/p&gt;
&lt;h3 id=&#34;431-evaluating-your-future-manager&#34;&gt;4.3.1. Evaluating your future manager&lt;/h3&gt;
&lt;p&gt;I hate micro-managers. The absolute worst manager would be one who&amp;rsquo;s constantly
looking over my shoulder and my teammates&#39;. In a manager I&amp;rsquo;m also looking for
somebody who&amp;rsquo;s 1) cool-headed and 2) who can be a good &amp;ldquo;shield&amp;rdquo;.
Concretely this means somebody who&amp;rsquo;ll fight to keep the team focused on a
minimum number of projects, and who will switch priorities only when absolutely
necessary. The third thing I&amp;rsquo;m looking for: someone who can coach, be
understanding, and listen.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s hard to probe for these things directly but I&amp;rsquo;ll tell you my personal
opinion on what you can look for &lt;em&gt;in an interview setting&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;The person you are talking to is more likely to be a &lt;strong&gt;bad manager&lt;/strong&gt; if they&amp;hellip;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;have a tendency to talk a lot&lt;/li&gt;
&lt;li&gt;get animated easily, are overly enthusiastic&lt;/li&gt;
&lt;li&gt;interrupt you at any point&lt;/li&gt;
&lt;li&gt;have a tendency to focus the discussion instead of opening it up&lt;/li&gt;
&lt;li&gt;did a lot of impressive technical work in the recent past&lt;/li&gt;
&lt;li&gt;are first-time managers (sorry, I have to put this in here!)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And here are some positive attributes. The person you are talking to is more
likely to be a &lt;strong&gt;good manager&lt;/strong&gt; if they&amp;hellip;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;ask good questions&lt;/li&gt;
&lt;li&gt;look interested in the answers. Bonus points for taking notes during interviews&lt;/li&gt;
&lt;li&gt;tend to stay high-level&lt;/li&gt;
&lt;li&gt;are terse/concise when they speak&lt;/li&gt;
&lt;li&gt;feel underwhelming, not that impressive&lt;/li&gt;
&lt;li&gt;smile, are positive&lt;/li&gt;
&lt;li&gt;get personal and tend to ask questions &amp;ldquo;out of the blue&amp;rdquo; to open up
discussion. For example, during your interview: &amp;ldquo;so who got you interested in
computers in the first place?&amp;rdquo; &amp;ldquo;have you thought about technical leadership?
Is that something you&amp;rsquo;d like to do down the road?&amp;rdquo;, etc.&lt;/li&gt;
&lt;li&gt;have a long history of being managers. Bonus points if they&amp;rsquo;ve done it at
multiple companies. Extra bonus points if they have a non-CS background.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;432-interviewing-teammates&#34;&gt;4.3.2. Interviewing teammates&lt;/h3&gt;
&lt;p&gt;Teammates are a bit easier to gauge. What makes
an ideal teammate to me? Somebody who&amp;rsquo;s willing to spend time to show me the
ropes and obscure tips to boost my productivity. Somebody who&amp;rsquo;s willing to say
&amp;ldquo;I don&amp;rsquo;t know&amp;rdquo; and learn from me when I can teach them something they don&amp;rsquo;t
know. Somebody who&amp;rsquo;ll happily take ownership of an idea that isn&amp;rsquo;t their own.
Somebody who says &amp;ldquo;hi&amp;rdquo; when you cross paths in the office or outside (a nod of
acknowledgment and a smile goes a long way). Somebody who admits to making
mistakes without trying to cover them up.&lt;/p&gt;
&lt;p&gt;How to evaluate this when you&amp;rsquo;re talking 1-1 to someone? The person you are
talking to is likely to be a &lt;strong&gt;bad teammate&lt;/strong&gt; if they&amp;hellip;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;interrupt you at any point&lt;/li&gt;
&lt;li&gt;are easily distracted and don&amp;rsquo;t pay attention to what you&amp;rsquo;re saying/writing&lt;/li&gt;
&lt;li&gt;take the interview process or themselves too seriously&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Conversely the person you are talking to is likely to be a &lt;strong&gt;good teammate&lt;/strong&gt; if
they&amp;hellip;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;smile; are enthusiastic when they talk about their job and the team&lt;/li&gt;
&lt;li&gt;are more interested in hearing about your technical expertise than explaining
theirs or the team&amp;rsquo;s&lt;/li&gt;
&lt;li&gt;are able to give you useful hints (use the power of hindsight here. Sometimes
the hint won&amp;rsquo;t feel helpful on the spot, but you&amp;rsquo;ll see its value later on.
That&amp;rsquo;s fine and correlates with good teammates in my experience)&lt;/li&gt;
&lt;li&gt;tend to explain the context of the problem or answers they&amp;rsquo;re giving&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;433-gauging-work-culture&#34;&gt;4.3.3. Gauging work culture&lt;/h3&gt;
&lt;p&gt;Work culture constantly shifts within a company. Very often it&amp;rsquo;s not consistent
across teams. Heck, &lt;em&gt;you&lt;/em&gt; may change and consider a culture &amp;ldquo;cool&amp;rdquo; now and
&amp;ldquo;awful&amp;rdquo; in a few years. That&amp;rsquo;s certainly happened to me.&lt;/p&gt;
&lt;p&gt;At the time of writing my ideal work culture offers a good work-life balance. I
want to be able to sleep and spend weekends 100% disconnected when I feel like
it (if I&amp;rsquo;m on-call, fine &amp;ndash; that&amp;rsquo;s a planned thing). I value work cultures with
an emphasis on social good will (help each other, be positive, teach/learn from
your neighbors, etc), (self)-education and transparency. See &lt;a href=&#34;https://arnaudbrousseau.com/notes/values.html&#34;&gt;this
post&lt;/a&gt; for my values overall.&lt;/p&gt;
&lt;p&gt;Now onto how to evaluate this in an interview setting. Some of these criteria
are self-explanatory; others require that you ask specific questions to your
interviewers. Most interviewers reserve some time at the end of their interviews
specifically for this. An immense majority of recruiters are be happy to
set up additional calls if you didn&amp;rsquo;t have time to ask all your questions.
Without further ado, the company you&amp;rsquo;re interviewing for is likely to have a
&lt;strong&gt;bad culture&lt;/strong&gt; if:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;there&amp;rsquo;s only White/Asian males in their 20s/30s on your interview panel&lt;/li&gt;
&lt;li&gt;a large part of the team-building happens outside of work hours (&amp;ldquo;the team
generally hangs out on Friday nights&amp;rdquo; &amp;ndash; Ugh. Does this mean if I don&amp;rsquo;t come
Friday night I&amp;rsquo;ll miss out?)&lt;/li&gt;
&lt;li&gt;your interviewers are intimidating (putting pressure on instead of trying to
take it off you)&lt;/li&gt;
&lt;li&gt;there are very few senior engineers and a lot of first-time managers&lt;/li&gt;
&lt;li&gt;the leadership team has seen a lot of departures in the recent past&lt;/li&gt;
&lt;li&gt;people pride themselves on working long hours or not taking vacation&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Conversely what I&amp;rsquo;m looking for; the company you&amp;rsquo;re interviewing for is likely
to have a &lt;strong&gt;good culture&lt;/strong&gt; if:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Teams are fluid &amp;ndash; this means knowledge gets around the company and fewer
silos exist&lt;/li&gt;
&lt;li&gt;There&amp;rsquo;s a default flexible work arrangement (everyone can choose to work
from home on given days)&lt;/li&gt;
&lt;li&gt;There&amp;rsquo;s an established on-call rotation &amp;ndash; if there&amp;rsquo;s a rotation, there&amp;rsquo;s
usually runbooks, calendars, and incident response procedures!&lt;/li&gt;
&lt;li&gt;No code goes to production unless reviewed (cowboy shipping is usually
indicative of a brash engineering culture)&lt;/li&gt;
&lt;li&gt;The company has a good number of non-engineering employees. In my experience
this helps balance egos and somewhat limit the nonsense sometimes generated by
engineering-first cultures. That&amp;rsquo;s only valid if non-engineers employees
interact meaningfully with the rest of the company!  Say if there&amp;rsquo;s a large
number of sales people in a different building, or a large number of warehouse
workers in a different city, the impact on the work culture you&amp;rsquo;ll experience
as an engineer is zero&amp;hellip;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;44-reflection-on-interviewing-pipelines-and-processes&#34;&gt;4.4. Reflection on interviewing pipelines and processes&lt;/h2&gt;
&lt;p&gt;I&amp;rsquo;ve been through a few interviewing pipelines recently. Below are some really
good ideas I&amp;rsquo;ve seen implemented in the wild. If you&amp;rsquo;re a recruiter or an
engineer in charge of some part of a recruiting pipeline, this section is for
you!&lt;/p&gt;
&lt;h3 id=&#34;441-automatically-graded-coding-test&#34;&gt;4.4.1. Automatically graded coding test&lt;/h3&gt;
&lt;p&gt;This saves a ton of time, and can often replace an expensive and biased (because
it involves the judgment of a single person) &amp;ldquo;phone screen&amp;rdquo; or &amp;ldquo;video call&amp;rdquo; with
an engineer.&lt;/p&gt;
&lt;p&gt;While we&amp;rsquo;re on the subject of coding tests: some companies opt for a &amp;ldquo;take home
assignment&amp;rdquo;. In my experience this can be a good idea but make sure to set a
strict time limit (target under an hour &amp;ndash; if longer than that a lot of good
candidates will lose interest) and grade the test based on objective criteria
established ahead of time.&lt;/p&gt;
&lt;h3 id=&#34;442-realistic-interviews&#34;&gt;4.4.2. Realistic interviews&lt;/h3&gt;
&lt;p&gt;During on-site interviews: focus on what&amp;rsquo;s difficult to assess! In my opinion,
on-site interviewers should steer clear of coding questions as much as possible.
The best way to know whether a candidate would be good to work with is to
simulate working with them! Try pair programming. Try whiteboarding systems. Try
simulating the experience of finding/fixing a bug together! How about reviewing
and discussing a piece of real code?&lt;/p&gt;
&lt;p&gt;Quite frankly I don&amp;rsquo;t understand why this isn&amp;rsquo;t more common. The fact that
Google, a company I deeply admire for their ethos and ability to innovate,
sticks to whiteboarded algorithm questions (for the most part&amp;hellip;they do have
design questions for senior engineers though) is baffling.&lt;/p&gt;
&lt;h3 id=&#34;443-no-surprises-interviews&#34;&gt;4.4.3 No-surprises interviews&lt;/h3&gt;
&lt;p&gt;Interviews do not have to feel like taking an exam. Why not communicate the
names of the interviewers, their teams, and rough subjects of the interviews
ahead of time? When I&amp;rsquo;m working on something new at work or when I&amp;rsquo;m called to
go to a meeting with a new group, I&amp;rsquo;m given notice on the agenda and topic. I
see no reason why interviews should be different.&lt;/p&gt;
&lt;p&gt;A bad schedule example:&lt;/p&gt;
&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;9am: meet and greet&lt;/li&gt;
&lt;li&gt;9:15am-10am: coding interview&lt;/li&gt;
&lt;li&gt;10am-10:45am: coding interview&lt;/li&gt;
&lt;li&gt;10:45am-11:30am: design interview&lt;/li&gt;
&lt;li&gt;11:30am-12:30pm: lunch break&lt;/li&gt;
&lt;li&gt;12:30pm-1:15pm: coding interview&lt;/li&gt;
&lt;li&gt;1:15pm-2pm: coding interview&lt;/li&gt;
&lt;li&gt;2pm-2:15pm: wrap up&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;p&gt;A better example:&lt;/p&gt;
&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;9am: recruiter will meet you in the lobby and walk you to your room for the
day&lt;/li&gt;
&lt;li&gt;9:15am-10am: coding interview with Sarah, engineer on the Payments team.
This will focus on tree-like structures and performance&lt;/li&gt;
&lt;li&gt;10am-10:45am: coding interview with John, senior engineer on our
Infrastructure team. Focus will be on caches in the context of web
applications as well as code quality&lt;/li&gt;
&lt;li&gt;10:45am-11:30am: design interview with Jane from our data science team.
You&amp;rsquo;ll get to talk about data pipelines and associated technical trade-offs&lt;/li&gt;
&lt;li&gt;11:30am-12:30pm: lunch break&lt;/li&gt;
&lt;li&gt;12:30pm-1:15pm: coding interview with Noah, engineer on the Platform team.
This interview will focus on finding a bug in one of our internal web
frameworks used in our microservices fleet&lt;/li&gt;
&lt;li&gt;1:15pm-1:30pm: wrap up with your recruiter, to shield questions and escort
you out of our HQ&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;p&gt;Sure candidates will study ahead of time. But that a good outcome! I&amp;rsquo;m betting
that this would lead to higher-quality interviews overall and a better
experience for both candidates and interviewers.&lt;/p&gt;
&lt;h1 id=&#34;5-a-final-offering-my-personal-todo-list&#34;&gt;5. A final offering: my personal TODO list&lt;/h1&gt;
&lt;p&gt;To conclude this blog post (that&amp;rsquo;s the last section! Good job making it this
far!) here is the precise list of things I did to prepare myself for interviews
at the end of 2018. I interviewed for backend/full-stack software engineering
positions, with Python as my language of choice whenever coding was needed.
This list may not be as useful if you&amp;rsquo;re interviewing for something vastly
different.&lt;/p&gt;
&lt;p&gt;Below I graded each item from 1 to 10 with the power of hindsight (&amp;ldquo;Looking back, was this
item useful for my interviews?&amp;quot;).&lt;/p&gt;
&lt;p&gt;Items related to &lt;strong&gt;interview prep in general&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;(4) Watch &lt;a href=&#34;https://www.facebook.com/Engineering/videos/10152735806862200/&#34;&gt;What to Expect During the Recruiting Process&lt;/a&gt; &amp;ndash; Facebook specific, but generally applicable&lt;/li&gt;
&lt;li&gt;(10) Go through &lt;a href=&#34;https://www.interviewcake.com/&#34;&gt;InterviewCake&lt;/a&gt;. Yes it&amp;rsquo;s paid content but it&amp;rsquo;s worth your money. Especially:
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.interviewcake.com/question/python/cake-thief?section=dynamic-programming-recursion&amp;amp;course=fc1&#34;&gt;InterviewCake&amp;rsquo;s &amp;ldquo;Cake Thief&amp;rdquo; question&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.interviewcake.com/question/python/balanced-binary-tree?section=dynamic-programming-recursion&amp;amp;course=fc1&#34;&gt;InterviewCake&amp;rsquo;s &amp;ldquo;Binary Tree balancing&amp;rdquo; question&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.interviewcake.com/question/python/coin?section=dynamic-programming-recursion&amp;amp;course=fc1&#34;&gt;InterviewCake&amp;rsquo;s &amp;ldquo;Making change&amp;rdquo; question&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.interviewcake.com/question/python/url-shortener&#34;&gt;InterviewCake&amp;rsquo;s &amp;ldquo;URL Shortener&amp;rdquo; design question&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;(4) Read through Google&amp;rsquo;s interviewing guide&lt;/li&gt;
&lt;li&gt;(5) For Amazon application, review &lt;a href=&#34;https://www.amazon.jobs/en/landing_pages/in-person-interview&#34;&gt;https://www.amazon.jobs/en/landing_pages/in-person-interview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(8) Oldie but goodie: read &lt;a href=&#34;https://steve-yegge.blogspot.com/2008/03/get-that-job-at-google.html&#34;&gt;Get That Job At Google&lt;/a&gt; by Steve Yegge&lt;/li&gt;
&lt;li&gt;(10) Prepare answers to behavioral questions (see &amp;ldquo;Softskills&amp;rdquo; above)&lt;/li&gt;
&lt;li&gt;(4) Watch &lt;a href=&#34;https://www.facebook.com/Engineering/videos/10152735777427200/&#34;&gt;How to Crush Your Coding Interview&lt;/a&gt; &amp;ndash; Facebook specific, but generally applicable&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Items related to &lt;strong&gt;CS fundamentals&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;(4) &lt;a href=&#34;https://mrpandey.github.io/d3graphTheory&#34;&gt;https://mrpandey.github.io/d3graphTheory&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(10) How are hashmaps implemented?
&lt;ul&gt;
&lt;li&gt;Array of linked lists. Each list maps to a &amp;ldquo;bucket&amp;rdquo;&lt;/li&gt;
&lt;li&gt;To store a key/val pair, hash the key, then store it in a linked list starting at &amp;ldquo;key mod num(buckets)&amp;rdquo;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;(1) ETAGS (&lt;a href=&#34;https://en.wikipedia.org/wiki/HTTP_ETag&#34;&gt;https://en.wikipedia.org/wiki/HTTP_ETag&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;(10) Binary search trees, how to implement/use them?&lt;/li&gt;
&lt;li&gt;(8) What are balanced trees?&lt;/li&gt;
&lt;li&gt;(10) Hash table implementation. Big-O to insert/update/retrieve values?&lt;/li&gt;
&lt;li&gt;(10) Binary Search trees
&lt;ul&gt;
&lt;li&gt;implementation in Python&lt;/li&gt;
&lt;li&gt;Big-o for insertion, deletion, and searching&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;(6) Implement BST&amp;rsquo;s delete() method&lt;/li&gt;
&lt;li&gt;(10) Linked List
&lt;ul&gt;
&lt;li&gt;Implementation in Python&lt;/li&gt;
&lt;li&gt;Singly vs doubly&lt;/li&gt;
&lt;li&gt;Big-o for insertion, deletion, and retrieval by index&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;(8) Review how Dijkstra&amp;rsquo;s algorithm work&lt;/li&gt;
&lt;li&gt;(8) Implement Dijkstra&amp;rsquo;s algorithm in Python&lt;/li&gt;
&lt;li&gt;(8) Review A* algorithm (path finding)&lt;/li&gt;
&lt;li&gt;(8) Read chapter 3 of skiena&amp;rsquo;s algorithm book&lt;/li&gt;
&lt;li&gt;(4) Read &lt;a href=&#34;http://web.stanford.edu/class/cs166/lectures/05/Small05.pdf&#34;&gt;http://web.stanford.edu/class/cs166/lectures/05/Small05.pdf&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(10) Breath-first search and depth first search algorithms in graphs/trees&lt;/li&gt;
&lt;li&gt;(10) Graph questions to master:
&lt;ul&gt;
&lt;li&gt;Is there a path between two nodes in this undirected graph? (-&amp;gt; run BFS or DFS)&lt;/li&gt;
&lt;li&gt;What&amp;rsquo;s the shortest path between two nodes in this undirected, unweighted graph? (-&amp;gt; run BFS!)&lt;/li&gt;
&lt;li&gt;Can this undirected graph be colored with two colors? (-&amp;gt; run BST!)&lt;/li&gt;
&lt;li&gt;Does this undirected graph have a cycle? (-&amp;gt; run DFS!)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;(10) Sorting algorithms. How efficient is each of them? What are some kinds of inputs that work best on each of them?&lt;/li&gt;
&lt;li&gt;(10) ways to represent a graph in memory (objects and pointers, matrix, and adjacency list) — familiarize yourself with each representation and its pros and cons.&lt;/li&gt;
&lt;li&gt;(2) Bloom filters: &lt;a href=&#34;https://llimllib.github.io/bloomfilter-tutorial/&#34;&gt;https://llimllib.github.io/bloomfilter-tutorial/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(4) Implement a trie-tree&lt;/li&gt;
&lt;li&gt;(2) Implement a red/black tree in Python&lt;/li&gt;
&lt;li&gt;(4) Implement A* algorithm in Python&lt;/li&gt;
&lt;li&gt;(6) Binary Heaps
&lt;ul&gt;
&lt;li&gt;Implementation in Python&lt;/li&gt;
&lt;li&gt;Big-o for insert, popMin, getMin&lt;/li&gt;
&lt;li&gt;Know that binary heaps aren&amp;rsquo;t usually faster than BSTs, but are faster in practice and consume less memory (why?)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;(10) Dynamic Array (ArrayList). Implement and know how resizing works&lt;/li&gt;
&lt;li&gt;(8) Implement quick sort (&lt;a href=&#34;http://interactivepython.org/runestone/static/pythonds/SortSearch/TheQuickSort.html&#34;&gt;reference&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;(6) What are some techniques to balance BSTs?&lt;/li&gt;
&lt;li&gt;(6) What are B-trees?&lt;/li&gt;
&lt;li&gt;(2) Read about treaps: &lt;a href=&#34;https://en.wikipedia.org/wiki/Treap&#34;&gt;https://en.wikipedia.org/wiki/Treap&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(4) LeetCode (931 Todo, 12 Solved, 2 Attempted)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To prepare for &lt;strong&gt;backend/systems&lt;/strong&gt; questions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;(8) Reader/writer locks&lt;/li&gt;
&lt;li&gt;(8) Files in linux, file descriptors&lt;/li&gt;
&lt;li&gt;(8) What&amp;rsquo;s a socket?&lt;/li&gt;
&lt;li&gt;(1) What&amp;rsquo;s anycast DNS?&lt;/li&gt;
&lt;li&gt;(8) Normalization in dbs: &lt;a href=&#34;https://dba.stackexchange.com/questions/4622/when-should-you-denormalize/15798#15798&#34;&gt;StackOverflow answer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(10) DB indices: know that they speed up reads but slow down writes. They also take space and are implemented with B-trees&lt;/li&gt;
&lt;li&gt;(6) Mutexes/semaphores
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.feabhas.com/2009/09/mutex-vs-semaphores-%e2%80%93-part-1-semaphores/&#34;&gt;Part 1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.feabhas.com/2009/09/mutex-vs-semaphores-%e2%80%93-part-2-the-mutex/&#34;&gt;Part 2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.feabhas.com/2009/10/mutex-vs-semaphores-%e2%80%93-part-3-final-part-mutual-exclusion-problems/&#34;&gt;Part 3&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;(4) Monitors: &lt;a href=&#34;https://en.wikipedia.org/wiki/Monitor_%28synchronization%29&#34;&gt;wikipedia:Monitors&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(6) Deadlocks and other concurrency problems: &lt;a href=&#34;https://www.quora.com/How-should-I-prepare-for-concurrency-questions-that-are-asked-at-Dropbox-interviews/answer/Eric-Worrall-1&#34;&gt;Quora answer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(10) What&amp;rsquo;s the heap of a program? The stack? &lt;a href=&#34;https://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap&#34;&gt;SO answer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(4) Malloc: how does it work? &lt;a href=&#34;https://stackoverflow.com/questions/1119134/how-do-malloc-and-free-work&#34;&gt;SO answer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(4) How do system calls work in general? &lt;a href=&#34;https://stackoverflow.com/questions/499188/how-is-the-system-call-in-linux-implemented&#34;&gt;SO answer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(10) Threads vs processes: &lt;a href=&#34;https://stackoverflow.com/questions/200469/what-is-the-difference-between-a-process-and-a-thread/200473#200473&#34;&gt;SO answer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(6) Database indices: how are they implemented?&lt;/li&gt;
&lt;li&gt;(8) Understand deadlock, livelock, and how to avoid them.&lt;/li&gt;
&lt;li&gt;(6) how context switching works, how it&amp;rsquo;s initiated by the operating
system, and underlying hardware&lt;/li&gt;
&lt;li&gt;(2) How does process scheduling work&lt;/li&gt;
&lt;li&gt;(4) Green threads: what are they? See &lt;a href=&#34;http://wiki.c2.com/?GreenVsNativeThreads&#34;&gt;Green vs Native threads&lt;/a&gt; and &lt;a href=&#34;https://c9x.me/articles/gthreads/intro.html&#34;&gt;gthreads/intro.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(8) Use each one of the APIs described in &lt;a href=&#34;https://docs.python.org/2/library/threading.html&#34;&gt;https://docs.python.org/2/library/threading.html&lt;/a&gt; in a toy program to understand them better&lt;/li&gt;
&lt;li&gt;(8) Write a C program using epoll or kqueue&lt;/li&gt;
&lt;li&gt;(4) Know about nginx&amp;rsquo;s main blocks/configuration&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To prepare for &lt;strong&gt;design interviews&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;(10) Have an answer for NoSQL vs SQL&lt;/li&gt;
&lt;li&gt;(8) Design question primer: &lt;a href=&#34;https://github.com/donnemartin/system-design-primer#system-design-interview-questions-with-solutions&#34;&gt;donnemartin/system-design-primer#system-design-interview-questions-with-solutions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(10) distributed hash table system &amp;ndash; how to design one&lt;/li&gt;
&lt;li&gt;(10) How does consistent hashing work?&lt;/li&gt;
&lt;li&gt;(6) Read &lt;a href=&#34;https://www.quora.com/How-do-I-prepare-to-answer-design-questions-in-a-technical-interview?redirected_qid=1500023&#34;&gt;this Quora answer about design interviews&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(8) Watch &lt;a href=&#34;https://www.youtube.com/watch?v=PE4gwstWhmc&#34;&gt;How We&amp;rsquo;ve Scaled Dropbox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(2) Read &lt;a href=&#34;https://www.palantir.com/2011/10/how-to-ace-a-systems-design-interview/&#34;&gt;How To Ace A Systems Design Interview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(2) Read &lt;a href=&#34;https://www.facebook.com/careers/life/preparing-for-your-software-engineering-interview-at-facebook&#34;&gt;Preparing for Your Software Engineering Interview at Facebook&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(2) Read &lt;a href=&#34;http://www.benstopford.com/2015/04/28/elements-of-scale-composing-and-scaling-data-platforms/&#34;&gt;Composing and Scaling Data Platform&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(5) Read &lt;a href=&#34;https://engineering.linkedin.com/distributed-systems/log-what-every-software-engineer-should-know-about-real-time-datas-unifying&#34;&gt;The Log: What every software engineer should know about real-time data&amp;rsquo;s unifying abstraction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;(10) Read a bit about Nginx&amp;rsquo;s architecture (&lt;a href=&#34;https://www.aosabook.org/en/nginx.html&#34;&gt;link&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Do not fit in the above categories (&lt;strong&gt;miscellaneous&lt;/strong&gt;):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;(10) Go through the &lt;a href=&#34;https://triplebyte.com/&#34;&gt;TripleByte&lt;/a&gt; interviewing process&lt;/li&gt;
&lt;li&gt;(10) SQL review (JOINs especially)&lt;/li&gt;
&lt;li&gt;(7) Fearless salary negotiations (&lt;a href=&#34;https://www.amazon.com/Fearless-Salary-Negotiation-step-step/dp/0692568689/&#34;&gt;Amazon link&lt;/a&gt;)
&lt;ul&gt;
&lt;li&gt;Read fearless salary negotiation free sample&lt;/li&gt;
&lt;li&gt;Read fearless salary negotiation book&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Finally, what I &lt;strong&gt;did not do&lt;/strong&gt; (the items left on my giant TODO list
basically). I will never know if these would have been useful to do or
not&amp;hellip;but here they are anyway:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Complete &lt;a href=&#34;https://github.com/trimstray/test-your-sysadmin-skills#simple-questions&#34;&gt;this sysadmin focused quizz&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;How to deal with nested state problems with Redux?&lt;/li&gt;
&lt;li&gt;Topological Sort: Arranges the nodes in a directed, acyclic graph in a special order based on incoming edges.&lt;/li&gt;
&lt;li&gt;Minimum Spanning Tree: Finds the cheapest set of edges needed to reach all nodes in a weighted graph. (greedy works! Pick edges based on their weight)&lt;/li&gt;
&lt;li&gt;Tail Call Optimization: how does it work in Scheme or JS? Why don&amp;rsquo;t languages like Python or Java allow it?&lt;/li&gt;
&lt;li&gt;Read &lt;a href=&#34;https://www.interviewbit.com/courses/system-design/topics/interview-questions/&#34;&gt;the system design questions portion of InterviewBit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Review what Paxos is and how it works (&lt;a href=&#34;https://www.microsoft.com/en-us/research/uploads/prod/2016/12/paxos-simple-Copy.pdf&#34;&gt;Paxos Made Simple&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Read &lt;a href=&#34;https://orrsella.gitbooks.io/soft-eng-interview-prep/content/topics/system-architecture-examples.html&#34;&gt;this&lt;/a&gt; (about system design interviews)&lt;/li&gt;
&lt;li&gt;Read &lt;a href=&#34;http://martin.kleppmann.com/2015/05/11/please-stop-calling-databases-cp-or-ap.html&#34;&gt;Please Stop Calling Databases CP or AP&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Read &lt;a href=&#34;http://alvaro-videla.com/2015/12/learning-about-distributed-systems.html&#34;&gt;Learning About Distributed Systems&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Read &lt;a href=&#34;https://www.airpair.com/aws/posts/building-a-scalable-web-app-on-amazon-web-services-p1&#34;&gt;Building a Scalable Webapp on AWS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Given an N by N grid of positive integers which represent terrain heights, determine how many grid locations will have water flow over the continental divide (NxN diagonal, 1-1, 2-2, etc) when it rains, not including the divide itself.&lt;/li&gt;
&lt;li&gt;Know how red/black tree (&lt;a href=&#34;https://en.wikipedia.org/wiki/Red_black_tree&#34;&gt;wiki page&lt;/a&gt;) , splay trees or AVL trees  are implemented&lt;/li&gt;
&lt;li&gt;Read &lt;a href=&#34;https://akkadia.org/drepper/newni.pdf&#34;&gt;https://akkadia.org/drepper/newni.pdf&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Read &lt;a href=&#34;https://www.usenix.org/legacy/events/hotos03/tech/full_papers/vonbehren/vonbehren_html/index.html&#34;&gt;this paper about events&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Go through InterviewBit&lt;/li&gt;
&lt;li&gt;Review &lt;a href=&#34;https://github.com/trekhleb/javascript-algorithms/&#34;&gt;trekhleb/javascript-algorithms&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Do skiena&amp;rsquo;s book&amp;rsquo;s exercises&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://web.stanford.edu/class/cs166/&#34;&gt;http://web.stanford.edu/class/cs166/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Go through a few exercises in &lt;a href=&#34;http://greenteapress.com/wp/semaphores/&#34;&gt;http://greenteapress.com/wp/semaphores/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Review concepts listed at &lt;a href=&#34;https://github.com/leonardomso/33-js-concepts&#34;&gt;leonardomso/33-js-concepts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Read &lt;a href=&#34;https://www.usenix.org/system/files/conference/nsdi13/nsdi13-final170_update.pdf&#34;&gt;this paper about memcache scaling&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Read &lt;a href=&#34;https://web.stanford.edu/~ouster/cgi-bin/papers/lfs.pdf&#34;&gt;Why Events Are A Bad Idea (for high-concurrency servers)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Read &lt;a href=&#34;http://www.cs.utexas.edu/users/lorenzo/corsi/cs380d/papers/paper2-1.pdf&#34;&gt;Paxos Made Live - An Engineering Perspective&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You made it. You&amp;rsquo;re a hero. ♫ &lt;a href=&#34;https://www.youtube.com/watch?v=JSUIQgEVDM4&#34;&gt;This is the end&lt;/a&gt; ♪.&lt;/p&gt;
&lt;hr/&gt;
To Ryan N. and Jon L.: thank you so much for the valuable feedback on early
version of this article! You rock ❤
</description>
    </item>
    <item>
      <title>Personal Ethos and Values</title>
      <link>https://arnaudbrousseau.com/notes/values.html</link>
      <pubDate>Wed, 09 Jan 2019 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/values.html</guid>
      <description>&lt;p&gt;A great ex-colleague of mine &lt;a href=&#34;https://twitter.com/solarkennedy&#34;&gt;@solarkennedy&lt;/a&gt;
once gave a talk about engineering leadership and challenged the room, a group
of tech leads, to someday think hard and write down what their core values are.
I&amp;rsquo;ve been thinking about this on and off for a while, and I believe I&amp;rsquo;m ready to
start writing some things down.&lt;/p&gt;
&lt;h1 id=&#34;engineering&#34;&gt;Engineering&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;If you do something 3 times, think about writing it down (if it&amp;rsquo;s a process),
automating it or abstracting it (if it&amp;rsquo;s code)&lt;/li&gt;
&lt;li&gt;Lack of tests is worse than technical debt. What I mean by &amp;ldquo;technical debt&amp;rdquo; is
the usual: long functions, complex nested if/for/if/else/while loops, tangled
logic. Getting rid of technical debt is generally easy with
tests, and extremely hard without. Lack of tests organically produces
hard-to-remove technical debt; good test coverage enables regular tech debt
cleanups.&lt;/li&gt;
&lt;li&gt;I don&amp;rsquo;t believe in TDD. But I believe in good automated tests. My philosophy:
never test code manually. Test the code that you&amp;rsquo;ve written or modified with a
new or existing &lt;strong&gt;automated&lt;/strong&gt; test. Don&amp;rsquo;t be religious about writing the
test(s) first.&lt;/li&gt;
&lt;li&gt;Debuggers are vastly more efficient at finding bugs than print/log statements
or manual tests. Invest in learning how to use them. Then use them.&lt;/li&gt;
&lt;li&gt;Engineering ownership is the most challenging thing to scale. &amp;ldquo;Ownership&amp;rdquo; is
both &amp;ldquo;who do I talk to to modify X?&amp;rdquo; and &amp;ldquo;who fixes X when it misbehaves?&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Processes aren&amp;rsquo;t good or bad. They&amp;rsquo;re either good or bad &lt;strong&gt;fits&lt;/strong&gt;. The same
applies to engineering tools (think: programming languages, frameworks,
editors). When a change is warranted: focus on the &lt;em&gt;fit&lt;/em&gt; and make it better.&lt;/li&gt;
&lt;li&gt;A well-communicated, agreed-upon solution beats a technically better one
every time. Engineers tend to be introverts so knowing how to build coalitions
and how to create/communicate (technical) roadmaps is like having super-powers.&lt;/li&gt;
&lt;li&gt;Performance optimizations made at the product level (changing the UI, tweaking
the product requirements) have 10x more potential than optimizations made
anywhere else for that particular product. Hence performance and
product/design go hand-in-hand.&lt;/li&gt;
&lt;li&gt;Code is written first for other humans to read, then for machines to execute.
Optimize for human reading speed first and for machine execution speed
second.&lt;/li&gt;
&lt;li&gt;Software engineering is 1% writing code, 99% fixing it, tweaking it,
releasing it, testing it, monitoring it, deprecating it.&lt;/li&gt;
&lt;li&gt;Scout rule: when modifying code, leave it cleaner than you found it! Related:
&amp;ldquo;Be the change you want to see in the world&amp;rdquo; applies to code. Ask for
forgiveness instead of permission when it comes to changing code.&lt;/li&gt;
&lt;li&gt;KISS (Keep It Simple Stupid) &amp;gt; DRY (Don&amp;rsquo;t Repeat Yourself)&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;life&#34;&gt;Life&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Everything lies on a spectrum. Look for both ends of it, play &amp;ldquo;devil&amp;rsquo;s&amp;rdquo; advocate
as much as you can.&lt;/li&gt;
&lt;li&gt;What defines you shapes your identity and also a set of blind spots. Look for
how you talk about yourself to be aware of them.&lt;/li&gt;
&lt;li&gt;Comfort is a hardcore drug. Treat it like one, and expect withdrawal symptoms
if you overuse it&lt;/li&gt;
&lt;li&gt;Feelings are (sometimes unconscious) choices. More evidently: actions are
choices too. Take responsibility for both.&lt;/li&gt;
&lt;li&gt;The more money you have, the less important money should feel. Don&amp;rsquo;t let money
become more and more important instead; otherwise you give up one of the core
benefits of having money.&lt;/li&gt;
&lt;li&gt;Education is at the core of everything we do. At the core of successes and at
the core of failure.&lt;/li&gt;
&lt;li&gt;There is no &amp;ldquo;good&amp;rdquo; and &amp;ldquo;bad&amp;rdquo;. Just people with different education, values and
incentives.&lt;/li&gt;
&lt;li&gt;There is no afterlife. Enjoy this one while it lasts.&lt;/li&gt;
&lt;li&gt;God doesn&amp;rsquo;t exist, or at least not in the form described by religions. So make
the most of life or don&amp;rsquo;t, nobody is judging. Pressure off.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;love&#34;&gt;Love&lt;/h1&gt;
&lt;p&gt;Probably a lot of things to say on the topic but I&amp;rsquo;ve come to disagree with the
standard European Romantic approach. Here&amp;rsquo;s a poem (by Kahlil Gibran) which
reflects my updated view:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Let there be spaces in your togetherness&lt;br&gt;
And let the winds of the heavens dance between you&lt;br&gt;
[&amp;hellip;]&lt;br&gt;
Sing and dance together and be joyous, but let each one of you be alone&lt;br&gt;
Even as the strings of a lute are alone though they quiver with the same music.&lt;br&gt;
Give your hearts, but not into each other&amp;rsquo;s keeping.&lt;br&gt;
[&amp;hellip;]&lt;br&gt;
And stand together, yet not too near together:&lt;br&gt;
For the pillars of the temple stand apart,&lt;br&gt;
And the oak tree and the cypress grow not in each other&amp;rsquo;s shadow&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;For that reason I find the term of &amp;ldquo;partner&amp;rdquo; quite fitting to the idea of a
long-lasting relationship.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>What Every Programmer Should Know About Memory, really</title>
      <link>https://arnaudbrousseau.com/notes/what-every-programmer-should-know-about-memory-really.html</link>
      <pubDate>Sat, 15 Sep 2018 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/what-every-programmer-should-know-about-memory-really.html</guid>
      <description>&lt;p&gt;After 11 months of procrastinating I finally got around to reading &lt;a href=&#34;https://people.freebsd.org/~lstewart/articles/cpumemory.pdf&#34;&gt;&amp;ldquo;What Every
Programmer Should Know About Memory&amp;rdquo;&lt;/a&gt;. It was on my list of opened
Firefox tabs this whole time and I decided on a whim to print it, read it and
take notes in the process. I powered through 110 pages so you don&amp;rsquo;t have to!&lt;/p&gt;
&lt;p&gt;Below are the takeaways and key concepts that I found interesting or worth
keeping a reference to. Keep in mind that &lt;a href=&#34;https://people.freebsd.org/~lstewart/articles/cpumemory.pdf&#34;&gt;&amp;ldquo;What Every Programmer Should Know
About Memory&amp;rdquo;&lt;/a&gt; was published in 2007 and not revised since. I tried to
update the advice or links when I found it necessary. Let&amp;rsquo;s go.&lt;/p&gt;
&lt;h1 id=&#34;glossary&#34;&gt;Glossary&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;ALU: Arithmetic Logical Unit&lt;/li&gt;
&lt;li&gt;ASLR: Address Space Layout Randomization&lt;/li&gt;
&lt;li&gt;CAS: Column Address Selection&lt;/li&gt;
&lt;li&gt;CAS: Compare-and-Swap&lt;/li&gt;
&lt;li&gt;CPI: Cycles Per Instruction&lt;/li&gt;
&lt;li&gt;CPU: Central Processing Unit&lt;/li&gt;
&lt;li&gt;DCA: Direct Cache Access&lt;/li&gt;
&lt;li&gt;DDR SDRAM: Double Data Rate, Synchronous DRAM&lt;/li&gt;
&lt;li&gt;DDR1/DDR2/DDR3: marketing names for different types of Double Data Rate RAM&lt;/li&gt;
&lt;li&gt;DMA: Direct Memory Access&lt;/li&gt;
&lt;li&gt;DRAM: Dynamic RAM&lt;/li&gt;
&lt;li&gt;DSO: Data Shared Object&lt;/li&gt;
&lt;li&gt;EPT: Extended Page Tables (Intel)&lt;/li&gt;
&lt;li&gt;FB-RAM: Fully Buffered RAM&lt;/li&gt;
&lt;li&gt;FSB: Front Side Bus&lt;/li&gt;
&lt;li&gt;IPC: Instructions Per Cycle&lt;/li&gt;
&lt;li&gt;IPC: Inter-Process Communication (depends on context!)&lt;/li&gt;
&lt;li&gt;L1d: Layer 1 data (cache)&lt;/li&gt;
&lt;li&gt;L1i: Layer 1 instruction (cache)&lt;/li&gt;
&lt;li&gt;LL/SC: Load Link/Store Conditional&lt;/li&gt;
&lt;li&gt;LRU: Least Recently Used&lt;/li&gt;
&lt;li&gt;MESI: Modified Exclusive Shared Invalid (protocol)&lt;/li&gt;
&lt;li&gt;MMU: Memory Management Unit&lt;/li&gt;
&lt;li&gt;NPT: Nested Page Tables (AMD)&lt;/li&gt;
&lt;li&gt;NUMA: Non-Uniform Memory Architecture&lt;/li&gt;
&lt;li&gt;RAM: Random Access Memory&lt;/li&gt;
&lt;li&gt;RAS: Row Address Selection&lt;/li&gt;
&lt;li&gt;RFO: Request For Ownership&lt;/li&gt;
&lt;li&gt;RISC: Reduced Instruction Set Computer&lt;/li&gt;
&lt;li&gt;SATA: Serial Advanced Technology Attachment&lt;/li&gt;
&lt;li&gt;SDR SDRAM: Single Data Rate, Synchronous DRAM&lt;/li&gt;
&lt;li&gt;SIMD: Single Instruction Multiple Data&lt;/li&gt;
&lt;li&gt;SMC: Self-Modifying Code&lt;/li&gt;
&lt;li&gt;SMP: Symmetric Multi Processor&lt;/li&gt;
&lt;li&gt;SMT: Symmetric Multi-Threading (aka &amp;ldquo;hyperthreads&amp;rdquo;)&lt;/li&gt;
&lt;li&gt;SRAM: Static RAM&lt;/li&gt;
&lt;li&gt;SSE: Streaming SIMD Extensions&lt;/li&gt;
&lt;li&gt;TLB: Translation Lookaside Buffer&lt;/li&gt;
&lt;li&gt;TLS: Thread Local Storage&lt;/li&gt;
&lt;li&gt;USB: Universal Serial Bus&lt;/li&gt;
&lt;li&gt;VMM: Virtual Machine Manager&lt;/li&gt;
&lt;li&gt;dTLB: Data Translation Lookaside Buffer&lt;/li&gt;
&lt;li&gt;t(RCD): time(RAS-to-CAS Delay)&lt;/li&gt;
&lt;li&gt;t(RP): time(RAS Precharge)&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;computer-architecture&#34;&gt;Computer architecture&lt;/h1&gt;
&lt;p&gt;In standard architectures CPUs load values and write to physical memory (RAM)
through the &lt;a href=&#34;https://en.wikipedia.org/wiki/Front-side_bus&#34;&gt;FSB&lt;/a&gt; and the Northbridge. The Southbridge is known as &amp;ldquo;the
I/O bridge&amp;rdquo; and handles communications to USB, SATA, etc.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Direct_memory_access&#34;&gt;DMA&lt;/a&gt; is a way for the southbridge to store value into RAM without the
intervention of the CPU, and without clogging the FSB. This is really
important to handle long I/O transfers without involving the CPU.&lt;/p&gt;
&lt;p&gt;For computers with more than 1 CPU, the memory controllers are sometimes
integrated into the CPU, resulting in an architecture where each CPU has its
own RAM attached to it. Because the access time from CPU1 to its attached
memory and access time from CPU1 to CPU4&amp;rsquo;s attached memory differ, this
architecture is called NUMA (Non Uniform Memory Architecture.)&lt;/p&gt;
&lt;p&gt;The &amp;ldquo;NUMA factor&amp;rdquo; is the extra time needed to access remote memory.&lt;/p&gt;
&lt;h1 id=&#34;ram&#34;&gt;RAM&lt;/h1&gt;
&lt;p&gt;Computer memory (RAM) is made out of &lt;a href=&#34;https://en.wikipedia.org/wiki/Transistor&#34;&gt;transistors&lt;/a&gt; and
&lt;a href=&#34;https://en.wikipedia.org/wiki/Capacitor&#34;&gt;capacitors&lt;/a&gt;. Transistors are electronic components acting like
switches (they&amp;rsquo;re either &amp;ldquo;open&amp;rdquo; i.e. not conducting, or &amp;ldquo;closed&amp;rdquo; i.e.
conducting). Capacitors are components storing energy (they&amp;rsquo;re either &amp;ldquo;0&amp;rdquo; i.e. empty or &amp;ldquo;1&amp;rdquo; i.e. full)&lt;/p&gt;
&lt;p&gt;These transistors and capacitors are organized into memory cells.&lt;/p&gt;
&lt;p&gt;A cell of SRAM (static RAM) involves multiple capacitors/transistors. A cell of
DRAM (dynamic RAM) is made of a single transistor/capacitor pair:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/wepskam-sram-vs-dram.png&#34; alt=&#34;DRAM vs SRAM&#34;&gt;&lt;/p&gt;
&lt;p&gt;Since SRAM is more complex it is more expensive. But it&amp;rsquo;s much more stable than
DRAM. Usually computers have SRAM for CPU caches and DRAM for main memory.&lt;/p&gt;
&lt;p&gt;Something worth noting: DRAM needs to be periodically refreshed (data is
read and written back immediately) to prevent capacitor charges from decaying.
Because of these periodical refreshes some cache data is made unavailable and
this causes delay if they&amp;rsquo;re accessed during refresh cycles.&lt;/p&gt;
&lt;p&gt;DRAM access:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Memory controller makes the row address available on the address bus (RAS)&lt;/li&gt;
&lt;li&gt;Signals are read&lt;/li&gt;
&lt;li&gt;Memory controller makes the column address available on the bus (CAS)&lt;/li&gt;
&lt;li&gt;Cache line is read and data gets out of the RAM chip&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The timing of these steps is determined by the frequency of the clock and the characteristics of the RAM chip. In particular:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DDR1 uses both up and down edges of the signal to transmit data, without
changing clock frequency. It has an I/O buffer between the DRAM cell array
and the output signal (&amp;ldquo;double-pumped&amp;rdquo; address bus)&lt;/li&gt;
&lt;li&gt;DDR2 doubles the frequency of the I/O buffer and output signal (&amp;ldquo;quad-pumped&amp;rdquo;
address bus)&lt;/li&gt;
&lt;li&gt;DDR3 quadruples the frequency of the output signal and has an 8bit I/O buffer&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;cpu-cache-architecture&#34;&gt;CPU cache architecture&lt;/h1&gt;
&lt;p&gt;CPU caches are made of SRAM. Why are CPU caches a good idea?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;spatial locality: it&amp;rsquo;s likely that two pieces of data/code located close to
each other will be used together&lt;/li&gt;
&lt;li&gt;temporal locality: two pieces of data/code used at a given time are likely to
be reused again soon&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Typically the size of a CPU cache is 3 orders of magnitude lower than the main
memory. For 4GB of DRAM, the CPU cache would be 4MB.&lt;/p&gt;
&lt;p&gt;CPUs have multiple layers and types of cache:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;L1d: Layer 1 data cache&lt;/li&gt;
&lt;li&gt;L1i: Layer 1 cache, can contains either the raw bytes of instructions (&amp;ldquo;instruction cache&amp;rdquo;), or the decoded instructions (&amp;ldquo;trace cache&amp;rdquo;)&lt;/li&gt;
&lt;li&gt;L2: Layer 2  cache (usually unified, i.e. can cache data and code)&lt;/li&gt;
&lt;li&gt;L3: Layer 3 cache (ditto)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;CPU cores are almost entirely independent, but CPU threads are NOT independent.
They share almost everything including registers and caches.&lt;/p&gt;
&lt;p&gt;Concept of a &lt;a href=&#34;https://en.wikipedia.org/wiki/Word_(computer_architecture)&#34;&gt;word&lt;/a&gt;: it&amp;rsquo;s the smallest unit of memory, and natural unit
of data used by the CPU. It&amp;rsquo;s usually 32-bit or 64-bit, depending on the
architecture. Hear all that fuss about &amp;ldquo;64-bit binaries&amp;rdquo;? That&amp;rsquo;s why.&lt;/p&gt;
&lt;p&gt;Concept of a cache line: usually 64 bytes or so.&lt;/p&gt;
&lt;p&gt;Exclusive cache architecture: data is in L1d or L2, but not in both. This leads to faster cache line writes to L1d (no need to populate L2!)&lt;/p&gt;
&lt;p&gt;Inclusive cache architecture: data is in L1d and L2. This leads to faster
eviction from L1d, because the content doesn&amp;rsquo;t have to be written to L2 when
it&amp;rsquo;s done. The data is already in L2. That&amp;rsquo;s at the expense of slower writes to
L1d.&lt;/p&gt;
&lt;h1 id=&#34;multi-processor-caches&#34;&gt;Multi-Processor caches&lt;/h1&gt;
&lt;p&gt;SMP architecture: CPU caches do not work independently from each other,
and work to maintain a consistent view (&amp;ldquo;cache coherency&amp;rdquo;). To make that happen
the &lt;a href=&#34;https://en.wikipedia.org/wiki/MESI_protocol&#34;&gt;MESI protocol&lt;/a&gt; is used between the different CPU units. This ensures
that dirty cache lines (lines that are written to by a CPU) aren&amp;rsquo;t present in
any other cache, and that clean cache lines (read-only lines) can be shared
between as many caches as needed. The concept is a bit similar to
&lt;a href=&#34;https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock&#34;&gt;Readers-Writer Locks&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The MESI protocol is a state machine applied to each cache line. Each line can
be in one of 4 states: Modified (cache line is dirty and present in only one
cache), Exclusive (cache line is clean and exclusively present in one cache),
Shared (cache line is clean and present in multiple caches) and Invalid (cache
line is unused). To request ownership over a given cache line (S to E
transition for example) RFO messages are sent from core to core, causing
potential delays.&lt;/p&gt;
&lt;p&gt;Whenever possible a program should minimize accesses from different processors
and core to the same memory locations!&lt;/p&gt;
&lt;p&gt;Writing programs that take advantage of parallel processors is hard because the
underlying hardware has a shared, constrained resource: the bus from the CPU to
memory. Programs which cannot use CPU caches effectively perform poorly and
deplete this precious resource.&lt;/p&gt;
&lt;h1 id=&#34;cache-associativity&#34;&gt;Cache Associativity&lt;/h1&gt;
&lt;p&gt;A cache is &lt;strong&gt;fully associative&lt;/strong&gt; if all cache objects can be associated with any
cache entry. This leads to a better cache utilization, at the expense of slow
lookups. For a 4MB cache with 64B cache lines that&amp;rsquo;s already 65536 entries to
check. This makes cache lookup too slow (remember we&amp;rsquo;re talking about L1d,
where single-digit numbers of CPU cycles matter!).&lt;/p&gt;
&lt;p&gt;The opposite of a fully associative cache is a &lt;strong&gt;direct-mapped cache&lt;/strong&gt;, where
each cache line has a cache entry already mapped to it. This way lookups are
really fast, there&amp;rsquo;s only one entry to check. Of course this means the cache
isn&amp;rsquo;t well utilized.&lt;/p&gt;
&lt;p&gt;In practice caches use a mix of both. A cache line is directly mapped to a
set. Within that set the cache is then fully associative. Hence &amp;ldquo;set-associative
caches&amp;rdquo;. An &amp;ldquo;8-way set associativity&amp;rdquo; means that the cache is split in sets of 8
entries for example.&lt;/p&gt;
&lt;p&gt;The concept of &lt;em&gt;conflict misses&lt;/em&gt; refers to when two cache objects belong in the
same set. Storing one in the cache will cause eviction of the other regardless
of the state of the cache (there might be plenty of space!).&lt;/p&gt;
&lt;h1 id=&#34;cache-writes-policies&#34;&gt;Cache writes policies&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Write-through cache: when data is modified in the cache, main memory is
updated at the same time&lt;/li&gt;
&lt;li&gt;Write-back cache: cache lines are marked as &amp;ldquo;dirty&amp;rdquo; on write, and lines are
written to main memory only when the cache line is evicted. This performs
better is memory isn&amp;rsquo;t shared between processes&lt;/li&gt;
&lt;li&gt;Write combining cache: cache lines are committed to main memory in batches.
This is a really popular method for graphic cards.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When writes aren&amp;rsquo;t possible because the cache is full, most CPU caches use LRU
to evict entries and make space for new data.&lt;/p&gt;
&lt;h1 id=&#34;self-modifying-code&#34;&gt;Self-Modifying Code&lt;/h1&gt;
&lt;p&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Self-modifying_code&#34;&gt;Self-Modifying Code&lt;/a&gt; (SMC) is to avoid at all cost since
CPUs make the assumption that code pages are immutable. SMC is very hard to
produce anyway.&lt;/p&gt;
&lt;h1 id=&#34;hyperthreads&#34;&gt;Hyperthreads&lt;/h1&gt;
&lt;p&gt;Hyperthreads (also known as SMTs) are a way to allow time-sharing of the ALU.
Basically, when one hyperthread is blocked on I/O (busy accessing memory, say),
the other hyperthread can use the ALU to make progress.&lt;/p&gt;
&lt;p&gt;Hyperthreads &lt;em&gt;share all CPU resources and registers&lt;/em&gt;.&lt;/p&gt;
&lt;h1 id=&#34;critical-word-load--early-restart&#34;&gt;Critical Word Load &amp;amp; Early Restart&lt;/h1&gt;
&lt;p&gt;Critical Word Load &amp;amp; Early Restart is a technique to fetch a word in a cache
line so that the CPU is unblocked as fast as possible.&lt;/p&gt;
&lt;h1 id=&#34;virtual-memory&#34;&gt;Virtual Memory&lt;/h1&gt;
&lt;p&gt;A virtual memory page is a continuous block of virtual memory. Generally 4096 bytes.&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    #include stdio.h
    #include unistd.h

    int main(void) {
        printf(
            &#34;The page size for this system is %ld bytes.\n&#34;,
            sysconf(_SC_PAGESIZE)
        );
        return 0;
    }
&lt;/pre&gt;
&lt;p&gt;How is virtual memory mapped to physical memory? Virtual memory addresses are
32-bit (or 64-bit) values which point to a precise bit on a page.&lt;/p&gt;
&lt;p&gt;The page directory is stored in main memory at a predefined place (a special
register). A virtual address has 2 parts: the directory, and the offset. The
directory part of the address is used as a key in the page directory. This
gives the physical page. Then the offset is used to locate the precise bit the
virtual address points to.&lt;/p&gt;
&lt;p&gt;Usually there are multiple page directories, and virtual addresses have
multiple levels of indices. The process of converting the virtual indices into
a physical page index is called &lt;strong&gt;page tree walking&lt;/strong&gt;.&lt;/p&gt;
&lt;h1 id=&#34;tlb-caches&#34;&gt;TLB caches&lt;/h1&gt;
&lt;p&gt;TLB caches contain the result of page tree walking. Each entry is a mapping of
a virtual index to a physical index. Usually there are more than one TLB cache.
dTLB cache is used for data, iTLB for instructions, and L2TLB to minimize
misses of both dTLB and iTLB caches.&lt;/p&gt;
&lt;p&gt;The cost of a TLB cache miss is a page tree walk. Since TLB cache entries apply
to a whole memory page, a lot of addresses benefit from one TLB cache entry (as
many as fit on one page)&lt;/p&gt;
&lt;p&gt;TLB caches need to be flushed when memory pages are re-mapped (typically during
process &lt;a href=&#34;https://en.wikipedia.org/wiki/Context_switch&#34;&gt;context switches&lt;/a&gt;, calls to &lt;code&gt;munmap&lt;/code&gt;, etc). Note that
smart invalidation is possible: if the current process has a non-overlapping
virtual memory space with the process about to be scheduled on the CPU, no need
to flush TLB cache entries! A further optimization is to use process
identifiers such that frequently used context switches do not cause TLB cache
misses even when their virtual memory space overlaps (think process -&amp;gt; kernel
-&amp;gt; process swaps.)&lt;/p&gt;
&lt;h1 id=&#34;virtualized-memory&#34;&gt;Virtualized memory&lt;/h1&gt;
&lt;p&gt;VMMs create their own page table trees (&amp;ldquo;shadow table tree&amp;rdquo;). This prevents
faulty/rogue access by guest kernel to physical memory (only the host VMM has
access to true physical memory), at the cost of another page tree walk,
potentially. Be really care ful when touching memory mapping from a guest OS,
it&amp;rsquo;s likely more expensive!&lt;/p&gt;
&lt;p&gt;To work around this AMD and Intel have both come up with optimizations to make
VMM memory consumption go down and avoid host page tree walks: EPT and NPT are
both there to make end-to-end address translations cacheable (guest virtual
address all the way to host physical address)&lt;/p&gt;
&lt;h1 id=&#34;numa&#34;&gt;NUMA&lt;/h1&gt;
&lt;p&gt;Why NUMA? To get rid of the Northbridge as a bottleneck to access memory (in
NUMA each CPU has its own dedicated connection to memory.)&lt;/p&gt;
&lt;p&gt;With NUMA processes get their memory allocation randomly split between the
different memory nodes (&amp;ldquo;striping&amp;rdquo;). This makes it easy to migrate processes
and mitigate the effect of processes consuming a large amount of memory. Also,
memory is consumed equally across processor regions with striping.&lt;/p&gt;
&lt;p&gt;A process can select a different strategy for itself and its children. This is
called &lt;strong&gt;NUMA pinning&lt;/strong&gt;. See &lt;a href=&#34;https://linux.die.net/man/8/numactl&#34;&gt;numactl&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;An alternative strategy to pin tasks to a given set of CPUs and memory nodes
without having to modify their code is &lt;code&gt;cpuset&lt;/code&gt;s. &lt;code&gt;mount -t cpuset none /dev/cpuset&lt;/code&gt; will create a special filesystem with &lt;code&gt;cpus&lt;/code&gt;, &lt;code&gt;mems&lt;/code&gt; and &lt;code&gt;tasks&lt;/code&gt;
files in each folders. To create a new set, just create a new directory and
edit &lt;code&gt;tasks&lt;/code&gt; to schedule tasks onto that set. More at &lt;a href=&#34;https://linux.die.net/man/7/cpuset&#34;&gt;cpusets&lt;/a&gt;.&lt;/p&gt;
&lt;h1 id=&#34;cpu-cache-topology&#34;&gt;CPU cache topology&lt;/h1&gt;
&lt;p&gt;The cache topology is available at:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;/sys/devices/system/cpu/cpu*/cache/index*/type,level,maps&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/sys/devices/system/cpu/cpu*/cache/index*/level&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/sys/devices/system/cpu/cpu*/cache/index*/maps&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/sys/devices/system/cpu/cpu*/topology/physical_package_id&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/sys/devices/system/cpu/cpu*/topology/core_id&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/sys/devices/system/cpu/cpu*/topology/thread_siblings&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/sys/devices/system/node/node*/cpumap&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/sys/devices/system/node/node*/distance&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/proc/$PID/numa_maps&lt;/code&gt; shows the memory page allocation per processor&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;non-temporal-hints&#34;&gt;Non-temporal hints&lt;/h1&gt;
&lt;p&gt;If a programmer knows that some data or code isn&amp;rsquo;t going to be reused, they can
give hints about this through &lt;strong&gt;intrinsics&lt;/strong&gt; (functions build into the compiler
and inlined into the code depending on the architecture). See &lt;a href=&#34;https://software.intel.com/en-us/node/683901&#34;&gt;the Intel
docs&lt;/a&gt; and the associated &lt;a href=&#34;https://github.com/gcc-mirror/gcc/blob/dd7ed3c2c6481b6840919c8a26e0006a5b3e60b3/gcc/config/i386/emmintrin.h#L1456&#34;&gt;GCC header file&lt;/a&gt;,
intrinsics like &lt;code&gt;_mm_stream_si32&lt;/code&gt; let you stream data directly to the CPU
without populating caches. This is called a &lt;strong&gt;non-temporal hint&lt;/strong&gt;.&lt;/p&gt;
&lt;h1 id=&#34;optimizing-data-cache-access&#34;&gt;Optimizing data cache access&lt;/h1&gt;
&lt;p&gt;Make use of loaded cache line effectively! If you load data, use as much of it as possible. Avoid loading a cache line just to read one bit of it. This means:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Pack structures so that they fit onto as few cache lines as possible.&lt;/li&gt;
&lt;li&gt;Fit data that&amp;rsquo;s likely to be used together close together, and if possible on the same cache line&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Tool to help with structure packing: &lt;a href=&#34;https://linux.die.net/man/1/pahole&#34;&gt;pahole&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As a programmer, try to move the critical structure elements to the beginning,
and when accessing structure fields, access them in the order in which they&amp;rsquo;re
defined.&lt;/p&gt;
&lt;p&gt;When possible, tuning structures for better memory alignment can help so that
they aren&amp;rsquo;t accidentally spanning two cache lines when they could fit on one.
To do this, use &lt;a href=&#34;https://gcc.gnu.org/onlinedocs/gcc-3.3/gcc/Type-Attributes.html&#34;&gt;GCC&amp;rsquo;s &lt;code&gt;aligned&lt;/code&gt; attribute&lt;/a&gt; or
&lt;a href=&#34;https://linux.die.net/man/3/posix_memalign&#34;&gt;&lt;code&gt;posix_memalign&lt;/code&gt;&lt;/a&gt;. The tradeoff here is that alignment makes
the program&amp;rsquo;s overall footprint go up.&lt;/p&gt;
&lt;p&gt;If structures are big, it helps to split them into smaller structs before
loading them into memory to make better use of CPU caches (e.g. if a loop uses
a couple of fields for an array of items, make sure the items are as slim as
possible, ideally containing just the fields needed for the loop logic.)&lt;/p&gt;
&lt;h1 id=&#34;optimizing-instruction-cache-access&#34;&gt;Optimizing instruction cache access&lt;/h1&gt;
&lt;p&gt;The killer for L1i is unpredictable branches/jumps because CPU execution
pipelines rely heavily on branch prediction.&lt;/p&gt;
&lt;p&gt;If code executes well without causing a delay in the execution pipeline it&amp;rsquo;s
said it&amp;rsquo;s executed &amp;ldquo;without bubbles&amp;rdquo;. While in practice hard to hand-tune L1i
usage can be made better.&lt;/p&gt;
&lt;p&gt;Reducing the code footprint as much as possible is always good. This has to be
balanced with optimizations like loop unrolling and inlining. Relevant GCC
options: &lt;code&gt;-O2&lt;/code&gt; (optimize), &lt;code&gt;-O3&lt;/code&gt; (optimize harder!), &lt;code&gt;-finline-limit&lt;/code&gt; (to set
the limit beyond which functions should not be inlined)&lt;/p&gt;
&lt;p&gt;Code execution should be as linear as possible and as predictable as possible.
It&amp;rsquo;s possible to tell the compiler which branches are more likely to occur with
&lt;a href=&#34;https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html&#34;&gt;&lt;code&gt;__builtin_expect&lt;/code&gt;&lt;/a&gt;. GCC can then reorder blocks based on
branch prediction with &lt;code&gt;-freorder-blocks&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Code alignment can help as well. &lt;code&gt;-falign-functions&lt;/code&gt;, &lt;code&gt;-falign-jumps&lt;/code&gt;, and
&lt;code&gt;-falign-loops&lt;/code&gt; can do this automatically, but this is a trade-off between
execution speed and memory footprint.&lt;/p&gt;
&lt;h1 id=&#34;optimizing-tlb-usage&#34;&gt;Optimizing TLB usage&lt;/h1&gt;
&lt;p&gt;At a high level:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Reduce number of TLB misses&lt;/li&gt;
&lt;li&gt;Minimize the number of TLB directories&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Optimizing TLB usage thus means minimizing the number of pages that a program uses and minimizing the number of page faults.&lt;/p&gt;
&lt;p&gt;What&amp;rsquo;s a page fault? When a process attempts to access a memory location
unmapped in the MMU (hence uncached in the TLB cache). This can either be a soft page fault of a hard page fault. More about page fault &lt;a href=&#34;https://en.wikipedia.org/wiki/Page_fault&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;An extreme optimization to perform to improve TLB usage is to disable ASLR so
that the load addresses of the program&amp;rsquo;s stack, DSOs and heap are more
predictable. This has obvious security implications and is a bad idea generally
speaking.&lt;/p&gt;
&lt;h1 id=&#34;optimizing-memory-allocations&#34;&gt;Optimizing memory allocations&lt;/h1&gt;
&lt;p&gt;When a program needs to allocate memory for many small objects, avoid
allocating memory in small chunks. Instead, allocate in bulk with
&lt;a href=&#34;https://www.gnu.org/software/libc/manual/html_node/Allocation-in-an-Obstack.html&#34;&gt;&lt;code&gt;obstack&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s also important to minimize page faults if possible. A tool to analyze when
page faults occur is &lt;a href=&#34;https://pkgs.org/download/pagein&#34;&gt;&lt;code&gt;pagein&lt;/code&gt;&lt;/a&gt;. If you know some memory pages will be
needed soon it&amp;rsquo;s possible to use &lt;code&gt;nmap&lt;/code&gt; with &lt;code&gt;MAP_POPULATE&lt;/code&gt; to &lt;em&gt;pre-fault&lt;/em&gt; the
pages in and pay the latency cost upfront.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s also possible to tell the OS that a page will be needed soon with
&lt;a href=&#34;https://linux.die.net/man/3/posix_madvise&#34;&gt;&lt;code&gt;madvise&lt;/code&gt;&lt;/a&gt; (&lt;code&gt;POSIX_MADV_WILLNEED&lt;/code&gt;). This offers more granularity than
&lt;code&gt;nmap&lt;/code&gt; with &lt;code&gt;MAP_POPULATE&lt;/code&gt; (calls to &lt;code&gt;nmap&lt;/code&gt; usually allocate more than 1 memory
page!)&lt;/p&gt;
&lt;p&gt;Yet another option to reduce page faults is the use bigger page size! It can be
wasteful because memory is more likely to go unused. So it&amp;rsquo;s best to use larger
page sizes only for big memory allocations. &lt;code&gt;hugetlbfs&lt;/code&gt; is a special file
system containing huge pages ready to be allocated. The number of huge pages
available can be tuned with &lt;code&gt;/proc/sys/vm/nr_hugepages&lt;/code&gt;. When using a VMM, the
guest OS doesn&amp;rsquo;t have control over the physical memory. A solution is to use
&lt;a href=&#34;https://linux.die.net/man/2/shmget&#34;&gt;&lt;code&gt;shmget&lt;/code&gt;&lt;/a&gt; (System V shared memory) with &lt;code&gt;SHM_HUGETLB&lt;/code&gt; and a length set
to be a multiple of the host&amp;rsquo;s huge page size. Sometimes the host mounts a
&lt;code&gt;hugetlbfs&lt;/code&gt; for guests. That&amp;rsquo;s preferable.&lt;/p&gt;
&lt;h1 id=&#34;prefetching&#34;&gt;Prefetching&lt;/h1&gt;
&lt;p&gt;Hardware prefetching is controlled by the CPU and kicks in when 2 or more
misses in a row are seen. Some more complex patterns are recognized depending
on the CPU and architecture, but the gist is that hardware prefetching is hard
to tune. It&amp;rsquo;s also important to realize that hardware prefetching &lt;em&gt;cannot go
over page boundaries&lt;/em&gt;. It&amp;rsquo;d be unacceptable for a program to experience
prefetch-induced page faults. What if the prefetcher is wrong and tries to
page-in a chunk of memory that isn&amp;rsquo;t owned by the program?&lt;/p&gt;
&lt;p&gt;Programmers can give hints such that memory is prefetched through software.
This is done with &lt;a href=&#34;https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html&#34;&gt;&lt;code&gt;GCC&#39;s __builtin_prefetch&lt;/code&gt;&lt;/a&gt;. A value of 0
means &amp;ldquo;don&amp;rsquo;t keep in the cache&amp;rdquo;, 1 means &amp;ldquo;load into L3, if present&amp;rdquo;, 2 means
&amp;ldquo;load into L2&amp;rdquo; and 3 means &amp;ldquo;load into L1&amp;rdquo; (default).&lt;/p&gt;
&lt;p&gt;To optimize a program with prefetching:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;look at cache misses&lt;/li&gt;
&lt;li&gt;if it&amp;rsquo;s high, add prefetch builtins &lt;em&gt;one at a time&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;look at prefetch and cache miss counters to see if that&amp;rsquo;s effective&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;GCC has &lt;code&gt;-fprefetch-loop-arrays&lt;/code&gt; to autofetch loop arrays, but it can hurt more
than it helps. Measure carefully!&lt;/p&gt;
&lt;p&gt;To avoid manually adding prefetch hints it&amp;rsquo;s possible to tell GCC to add them automatically:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Compile with &lt;code&gt;-fprofile-generate&lt;/code&gt; (outputs a &lt;code&gt;.gcno&lt;/code&gt; file)&lt;/li&gt;
&lt;li&gt;Run the output with a representative workload (that&amp;rsquo;s hard, but the more
accurate the workload, the better the generated prefetches will be!). This
outputs a &lt;code&gt;.gcda&lt;/code&gt; file&lt;/li&gt;
&lt;li&gt;Compile the program again with &lt;code&gt;-fprofile-use &amp;lt;gcda file&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A common pitfall when using prefetching is that the code becomes hard to read
and maintain. For this &amp;ldquo;helper threads&amp;rdquo; are a good solution. They&amp;rsquo;re
hyperthreads that are synchronized with the main program (with &lt;a href=&#34;https://linux.die.net/man/2/futex&#34;&gt;&lt;code&gt;futex&lt;/code&gt;&lt;/a&gt;
or &lt;a href=&#34;http://www.cs.rpi.edu/academics/courses/fall04/os/c6/index.html&#34;&gt;POSIX thread synchronization primitives&lt;/a&gt;), and
their only role is to perform prefetching such that other threads make progress
as fast as possible.&lt;/p&gt;
&lt;p&gt;To schedule helper threads &lt;a href=&#34;https://linux.die.net/man/3/numa&#34;&gt;libnuma&lt;/a&gt; can be used to pin them to their
own hyperthread.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Speculative_execution&#34;&gt;Speculation&lt;/a&gt; is a special sort of prefetch, very low level. The
idea is to execute instructions ahead of time even though the result might not
be needed. It&amp;rsquo;s not widely available but it has the advantage of loading the
data directly into registers. It&amp;rsquo;s completely transparent to the programmer and
so low-level that it&amp;rsquo;s not available for tuning.&lt;/p&gt;
&lt;h1 id=&#34;direct-cache-access&#34;&gt;Direct Cache Access&lt;/h1&gt;
&lt;p&gt;DCA is a way for I/O to be written directly into L1d. A common use case is the
handling of ethernet packets. DCA enables packets to be stored in the cache such
that when the OS handles the associated interrupts the data is there ready to
use and already available in the cache.&lt;/p&gt;
&lt;h1 id=&#34;optimizing-multi-threaded-programs&#34;&gt;Optimizing Multi-threaded programs&lt;/h1&gt;
&lt;p&gt;In a threaded application be aware of the overhead of writing to the same
cache line from different threads. If this happens a lot of RFOs are sent back
and forth between the different CPUs, which leads to unnecessary delays.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s possible to give hints to segregate data with GCC&amp;rsquo;s &lt;a href=&#34;http://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Variable-Attributes.html&#34;&gt;&lt;code&gt;section&lt;/code&gt;
attribute&lt;/a&gt;. It&amp;rsquo;s also possible to enforce that data is made
available for each thread with &lt;a href=&#34;https://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Thread_002dLocal.html&#34;&gt;TLS&lt;/a&gt; through &lt;code&gt;__thread&lt;/code&gt;,
aka thread-local storage.&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    // `bar` is isolated in a &#34;.data.ro&#34; section
    int bar __attribute__((section(&#34;.data.ro&#34;))) = 42

    // Allocates a segment with this data **for each thread** (TLS)
    __thread int bar = 42
&lt;/pre&gt;
&lt;p&gt;General optimization advice:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Separate read-only from read-write variables with &lt;code&gt;__attribute__((section(...)))&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Group read-write variables which are used together in &lt;code&gt;struct&lt;/code&gt;s&lt;/li&gt;
&lt;li&gt;Move read-write variables which are often written to onto their own cache
line (this means adding padding where necessary with
&lt;code&gt;__attribute__((aligned(...)))&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;If a variable is used by multiple threads, move it to TLS.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Even without contention for access to the same cache line, parallel threads can
still cause a slowdown because the connection to memory is shared between all
cores and hyper-threads.&lt;/p&gt;
&lt;p&gt;If there&amp;rsquo;s contention for bandwidth to access memory, it&amp;rsquo;s possible to optimize
this by scheduling threads touching the same data set on the same CPU and
scheduling threads touching distinct data sets on different CPUs. This leads to
better CPU cache utilization, and ultimately less FSB traffic. To schedule
threads or processes on specific CPUs/cores, their &lt;strong&gt;affinity&lt;/strong&gt; can be adjusted
through &lt;a href=&#34;https://linux.die.net/man/2/sched_setaffinity&#34;&gt;&lt;code&gt;sched_set_affinity&lt;/code&gt;&lt;/a&gt; (for processes) and
&lt;a href=&#34;https://linux.die.net/man/3/pthread_setaffinity_np&#34;&gt;&lt;code&gt;pthread_setaffinity_np&lt;/code&gt;&lt;/a&gt; (for threads).&lt;/p&gt;
&lt;p&gt;In addition to adjusting affinity it&amp;rsquo;s good to tune the memory policy to make
sure pages are pinned to the right set of nodes. See &lt;a href=&#34;https://github.com/torvalds/linux/blob/master/mm/mempolicy.c&#34;&gt;memory
policies&lt;/a&gt; (&lt;code&gt;MPOL_BIND&lt;/code&gt;, &lt;code&gt;MPOL_PREFERRED&lt;/code&gt;, &lt;code&gt;MPOL_INTERLEAVE&lt;/code&gt;,
&lt;code&gt;MPOL_DEFAULT&lt;/code&gt;), &lt;a href=&#34;https://linux.die.net/man/2/set_mempolicy&#34;&gt;&lt;code&gt;set_mempolicy&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://linux.die.net/man/2/mbind&#34;&gt;&lt;code&gt;mbind&lt;/code&gt;&lt;/a&gt; to tune
this.&lt;/p&gt;
&lt;p&gt;When getting information about memory nodes and places where tasks are run
it&amp;rsquo;s crucial to be aware that this information is transient and can change
without notice! For instance don&amp;rsquo;t use &lt;code&gt;sched_getaffinity&lt;/code&gt; and use this
information throughout a process&amp;rsquo;s lifetime to make optimizations.&lt;/p&gt;
&lt;h1 id=&#34;atomicity&#34;&gt;Atomicity&lt;/h1&gt;
&lt;p&gt;There are 4 types of atomic operations implemented by CPUs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Bit test/set/clear instructions (see &lt;a href=&#34;https://en.wikipedia.org/wiki/Bit_Manipulation_Instruction_Sets&#34;&gt;the bit instruction set&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;LL/SC: &lt;a href=&#34;https://en.wikipedia.org/wiki/Load-link/store-conditional&#34;&gt;Load Link/Store Conditional&lt;/a&gt; is a pair of instructions. The
first one (&amp;ldquo;Load link&amp;rdquo;) loads a value from a memory address and  stores its
value in a special register. The second (&amp;ldquo;Store Conditional&amp;rdquo;) issues a write
only if the initial memory address wasn&amp;rsquo;t touched (this is determined based
on the value in the special register.&lt;/li&gt;
&lt;li&gt;CAS: &lt;a href=&#34;https://en.wikipedia.org/wiki/Compare-and-swap&#34;&gt;Compare-and-Swap&lt;/a&gt; is equivalent to LL/SC but is done in a single
instruction: &lt;code&gt;CAS(pointer, known_val, new_val)&lt;/code&gt; compares the value of
&lt;code&gt;pointer&lt;/code&gt; against &lt;code&gt;known_val&lt;/code&gt; (the value known to this thread). If and only
if the pointer points to &lt;code&gt;known_val&lt;/code&gt;, then it&amp;rsquo;s set to be &lt;code&gt;new_val&lt;/code&gt;. If
another thread touches the memory location pointed to by &lt;code&gt;pointer&lt;/code&gt; the write
fails. CAS is a more modern version of LL/SC.&lt;/li&gt;
&lt;li&gt;Atomic arithmetic instructions: while possible to implement any kind of
atomic arithmetic instructions with CAS and/or LL/SC, it&amp;rsquo;s slow. Some CPUs
have built-in atomic arithmetics. Use &lt;a href=&#34;http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Atomic-Builtins.html&#34;&gt;GCC&amp;rsquo;s &lt;code&gt;__atomic_*&lt;/code&gt;&lt;/a&gt; for
this.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There is still a problem with standard CAS-based operations called the &lt;a href=&#34;https://en.wikipedia.org/wiki/ABA_problem&#34;&gt;&amp;ldquo;ABA
problem&amp;rdquo;&lt;/a&gt; because CAS uses &amp;ldquo;the value is the same&amp;rdquo; as a signal for
&amp;ldquo;nothing has happened&amp;rdquo;. That&amp;rsquo;s wrong.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Transactional_memory&#34;&gt;Transactional memory&lt;/a&gt; is a solution to this. The concept
is similar to database transactions, and implemented with the help of a
transactional cache. The main difference between atomic operations and
transactional memory is that the former has to write to main memory to
guarantee atomicity. The latter doesn&amp;rsquo;t as long as the transaction cache is
sufficiently large. This means atomic operations are likely to be significantly
faster.&lt;/p&gt;
&lt;p&gt;One gotcha: the transactional cache is an exclusive cache, so data that isn&amp;rsquo;t
needed by a transaction should be moved to a different cache line (otherwise
writing to this seemingly unrelated data will cause the transaction to fail.)&lt;/p&gt;
&lt;h1 id=&#34;performance-tooling&#34;&gt;Performance tooling&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/OProfile&#34;&gt;&lt;code&gt;oprofile&lt;/code&gt;&lt;/a&gt;. See &lt;a href=&#34;http://oprofile.sourceforge.net/docs/intel-corei7-events.php&#34;&gt;list of Intel i7 events&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://perfmon2.sourceforge.net/man/pfmon.html&#34;&gt;&lt;code&gt;perfmon&lt;/code&gt;/&lt;code&gt;pfmon&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To identify bottlenecks, use CPI (Cycles per instruction) or IPC (the reverse)
instead of raw &amp;ldquo;instructions retired&amp;rdquo; counters. Ratios are usually much easier
to analyze.&lt;/p&gt;
&lt;p&gt;To query resource usage of a task:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://linux.die.net/man/2/getrusage&#34;&gt;&lt;code&gt;getrusage&lt;/code&gt;&lt;/a&gt; gets execution time, IPC messages, minor and major
faults and more.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&#34;https://linux.die.net/man/5/proc&#34;&gt;&lt;code&gt;proc&lt;/code&gt; filesystem&lt;/a&gt; exposes tons of useful stats at
&lt;code&gt;/proc/&amp;lt;PID&amp;gt;/stat&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To simulate CPU caches: &lt;code&gt;valgrind --tool=cachegrind&lt;/code&gt; (see &lt;a href=&#34;http://valgrind.org/docs/manual/cg-manual.html&#34;&gt;cachegrind&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;To analyze memory usage: &lt;code&gt;valgrind --tool=massif&lt;/code&gt; (see &lt;a href=&#34;http://valgrind.org/docs/manual/ms-manual.html&#34;&gt;massif&lt;/a&gt;), or
&lt;code&gt;memusage &amp;lt;program&amp;gt; &amp;lt;args&amp;gt;&lt;/code&gt; (see &lt;a href=&#34;http://man7.org/linux/man-pages/man1/memusage.1.html&#34;&gt;memusage&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;Aside on stacks: &lt;a href=&#34;https://linux.die.net/man/2/sigaltstack&#34;&gt;&lt;code&gt;signalstack&lt;/code&gt;&lt;/a&gt; is a function to let programs use
an alternative stack during signal handling. A thread stack is typically
allocated by parents through &lt;code&gt;nmap&lt;/code&gt; so it can be allocated anywhere. So it&amp;rsquo;s
not always possible to capture the full program&amp;rsquo;s memory usage with tools like
&lt;code&gt;massif&lt;/code&gt; which need the &lt;code&gt;valgrind&lt;/code&gt; runtime to know about stack limits.&lt;/p&gt;
&lt;h1 id=&#34;acknowledgements&#34;&gt;Acknowledgements&lt;/h1&gt;
&lt;p&gt;Although I&amp;rsquo;m here laying out the key concepts and takeaway, you should really
go read &lt;a href=&#34;https://people.freebsd.org/~lstewart/articles/cpumemory.pdf&#34;&gt;the original
document&lt;/a&gt; if what
is explained above seems interesting. Ulrich Drepper does a &lt;em&gt;fantastic&lt;/em&gt; job
being as terse as possible when explaining fundamental concepts related to
CPUs, caches and memory. The document is well-balanced, nicely structured, and
one of the few examples of long papers actually worth reading.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>The Full Stack Tech Interview</title>
      <link>https://arnaudbrousseau.com/notes/tech-interviews.html</link>
      <pubDate>Sun, 15 Jul 2018 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/tech-interviews.html</guid>
      <description>&lt;p&gt;Full-stack interviews are hard. I do a lot of interviewing at Yelp and I firmly
believe that there is a disconnect or misunderstanding happening.&lt;/p&gt;
&lt;p&gt;Candidates (especially fresh graduates) expect to be grilled on fundamental computer
science questions. I, on the other hand, am looking for my next colleague. Sure
it&amp;rsquo;s nice to talk about linked list and binary tree traversals but it&amp;rsquo;s only a
small portion of what software engineers talk about on the job.&lt;/p&gt;
&lt;p&gt;This post lists the topics that are relevant to software engineering based on
what I&amp;rsquo;ve experienced at Yelp (and yes, this includes CS fundamentals!). This should hopefully convince you that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;this list is way too long, both for the candidate (how can you expect them to
learn ALL of this?) and the interviewer (how can you expect to probe on all
these topics?)&lt;/li&gt;
&lt;li&gt;it&amp;rsquo;s silly to grill candidates on CS fundamentals over and over since it
represents such a small subset of what&amp;rsquo;s relevant day-to-day&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Towards the end I&amp;rsquo;ll close with some thoughts on culture fit and &amp;ldquo;soft&amp;rdquo;
questions that you can use to gauge a candidate on whether they are likely to
be a fit for your team (you can also use this to prepare yourself before
interviewing!)&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s start with the big list, roughly organized from backend to frontend.&lt;/p&gt;
&lt;h1 id=&#34;unix&#34;&gt;Unix&lt;/h1&gt;
&lt;p&gt;For an awesome rundown of what linux is like under the covers, see &lt;a href=&#34;https://www.gitbook.com/book/0xax/linux-insides/details&#34;&gt;Linux
Insides&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;common-directories&#34;&gt;Common directories&lt;/h2&gt;
&lt;p&gt;If you work in a Linux-based environment, having intuition on
what goes where generally speaking is a big productivity boost.&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    /
      /bin
      /boot
      /dev
      /etc
      /home
      /lib
      /media
      /mnt
      /opt
      /proc
      /root
      /sbin
      /sys
      /tmp
      /unix
      /usr
        /include
        /lib
        /libexec
        /local
        /share
      /var
        /log
        /mail
        /spool
        /tmp
&lt;/pre&gt;
&lt;h2 id=&#34;process-vs-threads&#34;&gt;Process vs Threads&lt;/h2&gt;
&lt;p&gt;In Unix:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Threads and processes are created by &lt;code&gt;fork&lt;/code&gt; and &lt;code&gt;clone&lt;/code&gt;, respectively. Both map to &lt;code&gt;do_fork&lt;/code&gt; internally.&lt;/li&gt;
&lt;li&gt;Processes do not share memory. &lt;code&gt;fork&lt;/code&gt; guarantees memory safety. Memory is still copied efficiently with copy-on-write semantics&lt;/li&gt;
&lt;li&gt;Threads are processes sharing memory with the other threads in their group&lt;/li&gt;
&lt;li&gt;Each thread has a pid and a &amp;ldquo;tgid&amp;rdquo; &amp;ndash; thread group ID. tgid and pid are the same for processes. Not necessarily for threads.&lt;/li&gt;
&lt;li&gt;To get the thread group ID: getpid (GetProcessID)&lt;/li&gt;
&lt;li&gt;To get the thread ID: gettid (GetThreadID)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;One way to think about the difference between threads and processes: when
&lt;code&gt;fork()&lt;/code&gt; is called the resulting &amp;ldquo;thread&amp;rdquo; (really a process!) gets a new tgid
and pid. When &lt;code&gt;clone()&lt;/code&gt; is called the resulting thread gets a new ID, aka thread
ID (to let the scheduler run it independently), but keeps the same pid.&lt;/p&gt;
&lt;p&gt;Note: &lt;code&gt;getpid&lt;/code&gt; returns the tgid, which is why &lt;code&gt;getpid&lt;/code&gt; called in different
threads within the same process will return the same result.&lt;/p&gt;
&lt;h2 id=&#34;file-descriptors&#34;&gt;File descriptors&lt;/h2&gt;
&lt;p&gt;File descriptors of processes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;0 stdin&lt;/li&gt;
&lt;li&gt;1 stdout&lt;/li&gt;
&lt;li&gt;2 stderr&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;daemons&#34;&gt;Daemons&lt;/h2&gt;
&lt;p&gt;Daemons are processes running in the background.
Daemons are recognized by the system as any processes whose parent process has
a PID of 1, which always represents the process init.
init is always the first process that is started when a Linux computer is
booted up and it remains on the system until the computer is turned off.
&lt;code&gt;init&lt;/code&gt; adopts any process whose parent process dies without waiting for the child
process&amp;rsquo;s status.
The common method for launching a daemon involves forking once or twice, and
making the parent (and grandparent) processes die while the child (or
grandchild) process begins performing its normal function.&lt;/p&gt;
&lt;h2 id=&#34;unix-file-types&#34;&gt;Unix File Types&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;File (-) &amp;ndash; &lt;code&gt;touch myfile&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Directory (d) &amp;ndash; &lt;code&gt;mkdir mydir&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Symbolic Links (l) &amp;ndash; &lt;code&gt;ln -s dest src&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Named pipes (p) &amp;ndash; &lt;code&gt;mkfifo mypipe&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Socket (s) &amp;ndash; &lt;code&gt;nc -lU mysocket&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Block device (b) &amp;ndash; (usually disks)&lt;/li&gt;
&lt;li&gt;Character device (c) &amp;ndash; &lt;code&gt;/dev/null&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;posix&#34;&gt;POSIX&lt;/h2&gt;
&lt;p&gt;&lt;b&gt;P&lt;/b&gt;ortable &lt;b&gt;O&lt;/b&gt;perating &lt;b&gt;S&lt;/b&gt;ystem &lt;b&gt;I&lt;/b&gt;nterface (POSIX) is a standard to
define basic operations such that systems implementing it are compatible (and
as programmers, working across them seems consistent).&lt;/p&gt;
&lt;p&gt;See &lt;a href=&#34;https://en.wikipedia.org/wiki/POSIX&#34;&gt;wiki:POSIX&lt;/a&gt; for more information.&lt;/p&gt;
&lt;h2 id=&#34;everything-is-a-file&#34;&gt;Everything is a file?&lt;/h2&gt;
&lt;p&gt;Everything is a file &lt;em&gt;descriptor&lt;/em&gt;!&lt;/p&gt;
&lt;h1 id=&#34;cs-fundamentals&#34;&gt;CS fundamentals&lt;/h1&gt;
&lt;p&gt;The bread-and-butter of full-stack interviews. Some great resources if you need
to brush up your CS fundamentals in Python:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;http://interactivepython.org/runestone/static/pythonds/index.html&#34;&gt;interactivepython.org&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Peter Norvig&amp;rsquo;s &lt;a href=&#34;https://github.com/norvig/pytudes&#34;&gt;Pytudes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;sorting-algorithms&#34;&gt;Sorting algorithms&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Bubble sort: go linearly through the array, swap two items if they&amp;rsquo;re not in
order. Repeat until array is sorted!&lt;/li&gt;
&lt;li&gt;Selection sort&lt;/li&gt;
&lt;li&gt;Insertion sort&lt;/li&gt;
&lt;li&gt;Shell sort&lt;/li&gt;
&lt;li&gt;Merge sort&lt;/li&gt;
&lt;li&gt;Quick sort&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;data-structures&#34;&gt;Data Structures&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Arrays:
&lt;ul&gt;
&lt;li&gt;Append: &lt;code&gt;[].append(item)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Insert: &lt;code&gt;[].insert(x, item)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Length: &lt;code&gt;len([])&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Removal: &lt;code&gt;[].pop(index)&lt;/code&gt; (index is the index of the removed element, defaults to -1)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Queue: implemented with an array as a backing store. Then &lt;code&gt;enqueue&lt;/code&gt;/&lt;code&gt;dequeue&lt;/code&gt; to interact with it.&lt;/li&gt;
&lt;li&gt;Deque: bi-directional queue. Also has an array as a backing store. Then &lt;code&gt;addFront&lt;/code&gt;/&lt;code&gt;addRear&lt;/code&gt;/&lt;code&gt;removeFront&lt;/code&gt;/&lt;code&gt;removeRear&lt;/code&gt; to interact with it.&lt;/li&gt;
&lt;li&gt;Stack: implemented as a class with an array as a backing store. Then &lt;code&gt;pop&lt;/code&gt;/&lt;code&gt;peek&lt;/code&gt;/&lt;code&gt;push&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Linked List:
&lt;ul&gt;
&lt;li&gt;Node: &lt;code&gt;self.data&lt;/code&gt;, &lt;code&gt;self.next&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;List: items are &lt;code&gt;Node&lt;/code&gt;s. &lt;code&gt;self.head&lt;/code&gt; is None to start with. To add a &lt;code&gt;Node&lt;/code&gt;, either point the head to the new Node, and the &lt;code&gt;newnode.next&lt;/code&gt; to the old head.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Trees:
&lt;ul&gt;
&lt;li&gt;Binary search trees (treaps)&lt;/li&gt;
&lt;li&gt;Balancing search trees, to keep the lookup time under a certain time complexity). See &lt;a href=&#34;https://en.wikipedia.org/wiki/Tree_rotation&#34;&gt;Tree Rotation&lt;/a&gt; and &lt;a href=&#34;http://web.stanford.edu/class/cs166/lectures/05/Small05.pdf&#34;&gt;these slides&lt;/a&gt; for more.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;heap-and-stack&#34;&gt;Heap and stack&lt;/h2&gt;
&lt;p&gt;The stack is memory that&amp;rsquo;s always LIFO (&lt;b&gt;L&lt;/b&gt;ast &lt;b&gt;I&lt;/b&gt;n &lt;b&gt;F&lt;/b&gt;irst &lt;b&gt;O&lt;/b&gt;ut) and
used to keep track of function calls and local variables. The stack is the
running tally of the current program&amp;rsquo;s execution. To remember this, think about
the famous &lt;code&gt;StackOverflow&lt;/code&gt; exception, which occurs when a function recurs into
itself too many times. It allocates memory onto the &lt;em&gt;stack&lt;/em&gt; again and again
until it&amp;rsquo;s full.&lt;/p&gt;
&lt;p&gt;The heap is a memory space of the size of the process&#39; virtual memory. Access to this memory is a bit slower but much larger. Languages like Java let you set this when you run programs: &lt;code&gt;-Xmx6g&lt;/code&gt; will set the maximum heap size to be 6G.&lt;/p&gt;
&lt;p&gt;Worth noting that threads typically share their heap but not their stack.&lt;/p&gt;
&lt;h2 id=&#34;garbage-collection&#34;&gt;Garbage collection&lt;/h2&gt;
&lt;p&gt;See &lt;a href=&#34;https://spin.atomicobject.com/2014/09/03/visualizing-garbage-collection-algorithms/&#34;&gt;this article&lt;/a&gt; for a summary. What matters:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;mark-and-sweep (or any other tracing-type GC) can handle cyclic references easily&lt;/li&gt;
&lt;li&gt;reference counting has more difficulties dealing with cyclic references but
is generally easier to implement and reason about.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;networking-and-protocols&#34;&gt;Networking and Protocols&lt;/h1&gt;
&lt;h2 id=&#34;http-protocol&#34;&gt;HTTP protocol&lt;/h2&gt;
&lt;p&gt;What&amp;rsquo;s HTTP? Depends on versions.&lt;/p&gt;
&lt;p&gt;HTTP/1.x is a text-based protocol. Requests are composed of a method, protocol
version, headers and optional body. Responses are composed of status code (200,
404, 503, 421, etc), headers and optional body.&lt;/p&gt;
&lt;p&gt;The best way to understand HTTP is to see it in raw action with telnet! Let&amp;rsquo;s
&amp;ldquo;GET&amp;rdquo; Google&amp;rsquo;s UK homepage:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    =&gt; telnet www.google.co.uk 80
    Trying 172.217.22.3...
    Connected to www.google.co.uk.
    Escape character is &#39;^]&#39;.
    GET / HTTP/1.1
    Host: www.google.co.uk
    User-Agent: arnaud
    [I pressed ENTER]
&lt;/pre&gt;
&lt;p&gt;And Google responds with:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    HTTP/1.1 200 OK
    Date: Mon, 15 Jan 2018 16:18:35 GMT
    Expires: -1
    Cache-Control: private, max-age=0
    Content-Type: text/html; charset=ISO-8859-1
    P3P: CP=&#34;This is not a P3P policy! See g.co/p3phelp for more info.&#34;
    Server: gws
    X-XSS-Protection: 1; mode=block
    X-Frame-Options: SAMEORIGIN
    Accept-Ranges: none
    Vary: Accept-Encoding
    Transfer-Encoding: chunked
    Connection: Keep-Alive
    Set-Cookie: ...
    Set-Cookie: ...

    2ae9
    &lt;!doctype html&gt;...rest of the response
&lt;/pre&gt;
&lt;p&gt;For an overview of all the possible headers, statuses, etc see &lt;a href=&#34;https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol&#34;&gt;this wikipedia article&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;What about HTTP/2? Most of the structure is the same, but HTTP/2&amp;rsquo;s major
difference lies in the fact that it&amp;rsquo;s a &lt;strong&gt;binary&lt;/strong&gt; protocol. Instead of the
newlines being separators, HTTP/2 relies on the concept of frames, messages and
streams.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a frame is the smallest unit, containing at a minimum a header and a stream ID&lt;/li&gt;
&lt;li&gt;a message is composed of several frames and maps to a &amp;ldquo;request&amp;rdquo; or &amp;ldquo;response&amp;rdquo;&lt;/li&gt;
&lt;li&gt;a stream is a flow of one or several messages&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;More info at &lt;a href=&#34;https://hpbn.co/http2/&#34;&gt;High-Performance Browser Networking&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;So, taking our example above, let&amp;rsquo;s GET Google&amp;rsquo;s homepage in HTTP/2. Can&amp;rsquo;t use
&lt;code&gt;telnet&lt;/code&gt; unfortunately. We need &lt;code&gt;openssl&lt;/code&gt; (&amp;gt; 1.0.2) to connect because HTTP/2 needs TLS, and since HTTP/2 is a binary protocol it&amp;rsquo;d be a pain to write a request manually.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m lazy and I haven&amp;rsquo;t actually done the work to formulate and
serialize a GET request with HTTP/2. I will get to that someday when I finish
reading &lt;a href=&#34;https://tools.ietf.org/html/rfc7540&#34;&gt;RFC7540&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;tcp-vs-udp&#34;&gt;TCP vs. UDP&lt;/h2&gt;
&lt;p&gt;TCP is reliable, it&amp;rsquo;ll retransmit data. UDP isn&amp;rsquo;t and won&amp;rsquo;t.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;TCP: &lt;b&gt;T&lt;/b&gt;ransmission &lt;b&gt;C&lt;/b&gt;ontrol &lt;b&gt;P&lt;/b&gt;rotocol&lt;/li&gt;
&lt;li&gt;UDP: &lt;b&gt;U&lt;/b&gt;ser &lt;b&gt;D&lt;/b&gt;atagram &lt;b&gt;P&lt;/b&gt;rotocol&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;From the man pages:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The TCP protocol provides reliable, flow-controlled, two-way transmission
of data. It is a byte-stream protocol used to support the &lt;code&gt;SOCK_STREAM&lt;/code&gt; abstraction.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;UDP is a simple, unreliable datagram protocol which is used to support
the &lt;code&gt;SOCK_DGRAM&lt;/code&gt; abstraction for the Internet protocol family.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&#34;tcp-protocol&#34;&gt;TCP protocol&lt;/h2&gt;
&lt;p&gt;Important topics for full-stack developers:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;TCP initial three-way handshake (SYN, SYN/ACK, ACK)&lt;/li&gt;
&lt;li&gt;TCP congestion control mechanisms: window size adjustments when packet loss
happens, and TCP slow start.&lt;/li&gt;
&lt;li&gt;TCP head-of-line blocking: if a packet is lost, no further data is delivered
until that packet is retransmitted&lt;/li&gt;
&lt;li&gt;TCP teardown: FIN, FIN-ACK, ACK&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;See:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Transmission_Control_Protocol#Protocol_operation&#34;&gt;Wikipedia:TCP&lt;/a&gt; for a quick refresher on the basics&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://hpbn.co/building-blocks-of-tcp/&#34;&gt;hbpn.co:building-blocks-of-tcp&lt;/a&gt; for more details on how these basics matter for web browsers/sites/users&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.joyent.com/blog/tcp-puzzlers&#34;&gt;TCP Puzzlers&lt;/a&gt; for some advanced
considerations on failure modes: and how the state of TCP can get out of sync
between client and server. An example might be a hard power-cycle, or the
socket file descriptor not being torn down correctly on either end.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;ssl-vs-tls&#34;&gt;SSL vs TLS&lt;/h2&gt;
&lt;p&gt;SSL (&lt;b&gt;S&lt;/b&gt;ecure &lt;b&gt;S&lt;/b&gt;ocket &lt;b&gt;L&lt;/b&gt;ayer) was released by netscape in the 90s. TLS
(&lt;b&gt;T&lt;/b&gt;ransport &lt;b&gt;L&lt;/b&gt;ayer &lt;b&gt;S&lt;/b&gt;ecurity) is the name SSL took once it was taken
over by IETF.&lt;/p&gt;
&lt;p&gt;For a good overview of the principles behind HTTPS and what actually happens when a TLS connection is established, see &lt;a href=&#34;http://www.moserware.com/2009/06/first-few-milliseconds-of-https.html&#34;&gt;this post&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;certificates-and-encryption&#34;&gt;Certificates and encryption&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Encryption: everyone should understand the basics of the &lt;a href=&#34;https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange&#34;&gt;Diffie-Hellman key
exchange&lt;/a&gt;,
which enables two parties to exchange secrets in the open.&lt;/li&gt;
&lt;li&gt;Difference between authentication and encryption. Encryption does &lt;strong&gt;not&lt;/strong&gt;
solve the problem of a man-in-the-middle.&lt;/li&gt;
&lt;li&gt;On the web, authentication is solved by the certificate architecture, and
relies on chained trust (we trust the current certificate because we trust
its issuer)&lt;/li&gt;
&lt;li&gt;Browsers ship with hardcoded lists of certificate authorities (CAs)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;dns&#34;&gt;DNS&lt;/h2&gt;
&lt;p&gt;DNS (&lt;b&gt;D&lt;/b&gt;omain &lt;b&gt;N&lt;/b&gt;ame &lt;b&gt;S&lt;/b&gt;ystem) queries are made by browsers to be able to
know which host to establish a connection to. DNS packets are transported over
UDP on port 53. Some resolvers use TCP. Here&amp;rsquo;s an example:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    =&gt; dig @208.67.222.222 google.com

    ; &lt;&lt;&gt;&gt; DiG 9.8.3-P1 &lt;&lt;&gt;&gt; @208.67.222.222 google.com
    ; (1 server found)
    ;; global options: +cmd
    ;; Got answer:
    ;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 46269
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

    ;; QUESTION SECTION:
    ;google.com.            IN  A

    ;; ANSWER SECTION:
    google.com.     300 IN  A   216.58.209.238

    ;; Query time: 76 msec
    ;; SERVER: 208.67.222.222#53(208.67.222.222)
    ;; WHEN: Mon Jan 15 19:31:33 2018
    ;; MSG SIZE  rcvd: 44
&lt;/pre&gt;
&lt;p&gt;For a great refresher on the basics/specs, head to &lt;a href=&#34;https://powerdns.org/hello-dns/basic.md.html&#34;&gt;powerdns.org:basic&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;unix-networking&#34;&gt;UNIX Networking&lt;/h2&gt;
&lt;p&gt;It&amp;rsquo;s not that important to know by heart how to code a client or a server from
scratch in C, but it&amp;rsquo;s important to understand which system calls are involved at a high level.&lt;/p&gt;
&lt;p&gt;For a client:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;getaddrinfo&lt;/code&gt;: get &lt;code&gt;servinfo&lt;/code&gt; which corresponds to the server we want to connect to&lt;/li&gt;
&lt;li&gt;&lt;code&gt;socket&lt;/code&gt;: create a new socket to holds the connection, from &lt;code&gt;servinfo&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;recv&lt;/code&gt;/&lt;code&gt;send&lt;/code&gt; (on &lt;code&gt;SOCK_STREAM&lt;/code&gt;-type sockets) or &lt;code&gt;sendto&lt;/code&gt; and &lt;code&gt;recvfrom&lt;/code&gt; (on &lt;code&gt;SOCK_DGRAM&lt;/code&gt;-type sockets): send data to and receive data from the server, via the socket we just created&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For a server:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;getaddrinfo&lt;/code&gt;: get &lt;code&gt;servinfo&lt;/code&gt; which corresponds to the server&amp;rsquo;s own IP (&lt;code&gt;hints.ai_flags == AI_PASSIVE&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;socket&lt;/code&gt;: create a socket to hold the connection, from &lt;code&gt;servinfo&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bind&lt;/code&gt;: to bind the socket to the port chosen (the port info is in &lt;code&gt;servinfo&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;listen&lt;/code&gt;: start waiting for clients to connect. Each connection is stored by the kernel into a common queue (the &amp;ldquo;accept queue&amp;rdquo;)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;accept&lt;/code&gt;: gets a connection from the accept queue and &amp;ldquo;accepts&amp;rdquo; it, by creating a socket and returning its file descriptor&lt;/li&gt;
&lt;li&gt;&lt;code&gt;recv&lt;/code&gt;/&lt;code&gt;send&lt;/code&gt; (on &lt;code&gt;SOCK_STREAM&lt;/code&gt;-type sockets) or &lt;code&gt;sendto&lt;/code&gt; and &lt;code&gt;recvfrom&lt;/code&gt; (on &lt;code&gt;SOCK_DGRAM&lt;/code&gt;-type sockets): receive data from and send data to a connected client, via the connection&amp;rsquo;s socket file descriptor.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;See &lt;a href=&#34;https://beej.us/guide/bgnet/html/single/bgnet.html&#34;&gt;Beej&amp;rsquo;s guide&lt;/a&gt; for a &lt;em&gt;way&lt;/em&gt; more complete picture.&lt;/p&gt;
&lt;h1 id=&#34;databases&#34;&gt;Databases&lt;/h1&gt;
&lt;h2 id=&#34;document-datastores-vs-relational-dbs-vs-graph-dbs&#34;&gt;Document datastores vs. relational DBs vs. graph DBs&lt;/h2&gt;
&lt;p&gt;Ultimately what matters during an interview is the knowledge that these 3 types
of databases are available, and know one of each type to model data.&lt;/p&gt;
&lt;h3 id=&#34;elasticsearch&#34;&gt;ElasticSearch&lt;/h3&gt;
&lt;p&gt;ElasticSearch is a popular example. To store data, you&amp;rsquo;d send an HTTP POST request (see &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html&#34;&gt;docs&lt;/a&gt;):&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    POST /$index/$type
    {...JSON of object...}
&lt;/pre&gt;
&lt;p&gt;To get data, send a GET request with a few parameters. For example:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    GET /_search
    {
      &#34;query&#34;: {
        &#34;bool&#34;: {
          &#34;must&#34;: [
            { &#34;match&#34;: { &#34;rating&#34;: &#34;5&#34;}},
            { &#34;match&#34;: { &#34;content&#34;: &#34;hipster&#34; }}
          ],
          &#34;filter&#34;: [
            { &#34;range&#34;: { &#34;publish_date&#34;: { &#34;gte&#34;: &#34;2018-01-01&#34; }}}
          ]
        }
      }
    }
&lt;/pre&gt;
&lt;h3 id=&#34;mysql&#34;&gt;MySQL&lt;/h3&gt;
&lt;p&gt;MySQL is the most basic datastore, used ubiquitously. MySQL uses straight up TCP to send queries.&lt;/p&gt;
&lt;p&gt;To insert data, use &lt;code&gt;INSERT&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    INSERT INTO review VALUES (&#39;review text&#39;, 4, 1234);
    # OR
    INSERT INTO review SET text=&#39;review text&#39; AND review_id=4 AND reviewer_id=1234;
&lt;/pre&gt;
&lt;p&gt;To get data use &lt;code&gt;SELECT&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    SELECT text, review_id FROM review WHERE reviewer_id=1234;
&lt;/pre&gt;
&lt;h3 id=&#34;neo4j&#34;&gt;Neo4j&lt;/h3&gt;
&lt;p&gt;I haven&amp;rsquo;t looked at graph databases a lot but if I had to look into one, it&amp;rsquo;d
be Neo4j, mostly because of the quality of the docs available.&lt;/p&gt;
&lt;p&gt;Interacting with Neo4j is done over HTTP. Queries are sent in plain text (Cypher instead of SQL) as part of a &amp;ldquo;statement&amp;rdquo; key in the body of the request.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://neo4j.com/docs/developer-manual&#34;&gt;Link to docs&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;acid&#34;&gt;ACID&lt;/h2&gt;
&lt;p&gt;Atomicity, Consistency, Isolation, Durability. These properties are fundamental
to defining proper database transactions.&lt;/p&gt;
&lt;p&gt;See &lt;a href=&#34;https://en.wikipedia.org/wiki/ACID&#34;&gt;wiki:ACID&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;cap-theorem&#34;&gt;CAP Theorem&lt;/h2&gt;
&lt;p&gt;Consistency (changes are atomic), Availability (remains accessible at all
times), and Partition Tolerance (small network outages do not cause an outage
or errors). The CAP theorem states that a datastore can only satisfy 2.&lt;/p&gt;
&lt;h1 id=&#34;python&#34;&gt;Python&lt;/h1&gt;
&lt;h2 id=&#34;how-is-python-interpreted&#34;&gt;How is Python interpreted?&lt;/h2&gt;
&lt;p&gt;Short version:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Python code (source.py)&lt;/li&gt;
&lt;li&gt;gets compiled to bytecode by a compiler (source.pyc)&lt;/li&gt;
&lt;li&gt;which gets fed into the Python interpreter to be executed&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here&amp;rsquo;s a &lt;a href=&#34;https://www.youtube.com/playlist?list=PLzV58Zm8FuBL6OAv1Yu6AwXZrnsFbbR0S&#34;&gt;YouTube
playlist&lt;/a&gt; if you enjoy this topic.&lt;/p&gt;
&lt;h2 id=&#34;virtualenv&#34;&gt;virtualenv&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;virtualenv&lt;/code&gt; is a tool to isolate Python code from python version and default
packages installed on a machine.&lt;/p&gt;
&lt;p&gt;To create a virtualenv:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    $ virtualenv --python=&#34;python3.6&#34;
&lt;/pre&gt;
&lt;p&gt;To get inside of it:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    $ source virtualenv_run/bin/activate
&lt;/pre&gt;
&lt;p&gt;Then install dependencies, run your code, etc. When you&amp;rsquo;re done: &lt;code&gt;deactivate&lt;/code&gt;
will take you out of the virtualenv.&lt;/p&gt;
&lt;h2 id=&#34;the-gil&#34;&gt;The GIL&lt;/h2&gt;
&lt;p&gt;The Global Interpreter Lock in Python is a mutex in CPython (the python
&lt;em&gt;interpreter&lt;/em&gt;) to control access to Python objects and prevent threads from all
executing code at once. Why? Because Python&amp;rsquo;s memory management system
(reference counting) is not thread safe.&lt;/p&gt;
&lt;h2 id=&#34;python-2x-vs-py3&#34;&gt;Python 2.x vs py3&lt;/h2&gt;
&lt;p&gt;There are lots of (small-ish) differences but the main one is the default type
for strings. In Python2 it defaults to &lt;code&gt;bytes&lt;/code&gt;. In python3 it defaults to
python2&amp;rsquo;s &lt;code&gt;unicode&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;encoding-decoding&#34;&gt;Encoding, Decoding&lt;/h2&gt;
&lt;p&gt;Something that all programmers should know.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;An encoding example: &lt;code&gt;utf-8&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;To decode &lt;strong&gt;from&lt;/strong&gt; bytes &lt;strong&gt;into&lt;/strong&gt; a string: &lt;code&gt;my_str = buffer.decode(&#39;utf-8&#39;)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;To encode a string &lt;strong&gt;into&lt;/strong&gt; bytes: &lt;code&gt;my_bytes = str.encode(&#39;utf-8&#39;)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;sorting-in-python&#34;&gt;Sorting in Python&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;sorted()&lt;/code&gt; if you want to keep a copy of the non-sorted items&lt;/li&gt;
&lt;li&gt;Use inline sorting if you don&amp;rsquo;t: &lt;code&gt;myarray.sort(key=lambda item: item[&#39;somekey&#39;])&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Python uses &lt;a href=&#34;https://github.com/python/cpython/blob/master/Objects/listsort.txt&#34;&gt;&amp;ldquo;timsort&amp;rdquo;&lt;/a&gt; by default&lt;/p&gt;
&lt;h2 id=&#34;namedtuple&#34;&gt;NamedTuple&lt;/h2&gt;
&lt;p&gt;Named tuples are a lightweight construct useful where you want immutable types:&lt;/p&gt;
&lt;pre class=&#34;brush:python&#34;&gt;
    Animal = namedtuple(&#39;Animal&#39;, [&#39;cuteness_factor&#39;, &#39;type&#39;, &#39;continent&#39;])
&lt;/pre&gt;
&lt;h2 id=&#34;classes&#34;&gt;Classes&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;New-style classes: &lt;code&gt;class Foo(object):&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Old-style classes: &lt;code&gt;class Foo:&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;What are the differences? Not much. See &lt;a href=&#34;https://wiki.python.org/moin/NewClassVsClassicClass&#34;&gt;this
wiki&lt;/a&gt;. Always lean towards
new-style classes if possible.&lt;/p&gt;
&lt;h2 id=&#34;metaclasses&#34;&gt;Metaclasses&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Metaclass programming is a last-resort option, avoid at all cost!&lt;/li&gt;
&lt;li&gt;Metaclasses are a way to programmatically create Python classes.&lt;/li&gt;
&lt;li&gt;Python classes are created with &lt;code&gt;type&lt;/code&gt;:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    &gt;&gt;&gt; print(type.__doc__)
    type(object_or_name, bases, dict)
    type(object) -&gt; the object&#39;s type
    type(name, bases, dict) -&gt; a new type
&lt;/pre&gt;
&lt;p&gt;This is all you need to know. For further details on this craziness, consult
&lt;a href=&#34;https://blog.ionelmc.ro/2015/02/09/understanding-python-metaclasses/&#34;&gt;this
article&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;inheritance&#34;&gt;Inheritance&lt;/h2&gt;
&lt;p&gt;For py2:&lt;/p&gt;
&lt;pre class=&#34;brush:python&#34;&gt;
    class Foo(Bar):

        def __init__(self, quux):
            super(Foo, self).__init__(quux)
&lt;/pre&gt;
&lt;p&gt;In py3 you can do:&lt;/p&gt;
&lt;pre class=&#34;brush:python&#34;&gt;
    class Foo(Bar):

        def __init__(self, quux):
            super().__init__(quux)
&lt;/pre&gt;
&lt;h2 id=&#34;abstract-base-classes-abc&#34;&gt;Abstract Base Classes (abc)&lt;/h2&gt;
&lt;pre class=&#34;brush:python&#34;&gt;
    &#34;&#34;&#34;Python 2.5&#34;&#34;&#34;
    class MyInterface:
        def foo(self):
            raise NotImplementedError
&lt;/pre&gt;
&lt;pre class=&#34;brush:python&#34;&gt;
    &#34;&#34;&#34;Python 2.6+&#34;&#34;&#34;

    class MyInterface(object):

        __metaclass__ = abc.ABCMeta

        @abc.abstractmethod
        def foo(self):
            raise NotImplementedError
&lt;/pre&gt;
&lt;pre class=&#34;brush:python&#34;&gt;
    &#34;&#34;&#34;Python 3&#34;&#34;&#34;
    class MyInterface(object, metaclass=abc.ABCMeta):

        @abc.abstractmethod
        def foo(self):
            raise NotImplementedError
&lt;/pre&gt;
&lt;h2 id=&#34;achieving-parallelism-multiprocessing-threading-and-gevent&#34;&gt;Achieving parallelism: &lt;code&gt;multiprocessing&lt;/code&gt;, &lt;code&gt;threading&lt;/code&gt; and &lt;code&gt;gevent&lt;/code&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;multiprocessing&lt;/code&gt; achieves parallelism by spawning subprocesses with &lt;code&gt;fork&lt;/code&gt;
or &lt;code&gt;spawn&lt;/code&gt; (e.g. &lt;code&gt;multiprocessing.set_start_method(&#39;spawn&#39;)&lt;/code&gt;).
See &lt;a href=&#34;https://docs.python.org/3.6/library/multiprocessing.html&#34;&gt;docs&lt;/a&gt; for more.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;threading&lt;/code&gt; achieves parallelism by spawning new threads. Threads are more
lightweight than processes and share memory with their parent. See
&lt;a href=&#34;https://docs.python.org/3.6/library/threading.html?highlight=threading#module-threading&#34;&gt;docs&lt;/a&gt;
for more.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;gevent&lt;/code&gt; is an abstraction implementing coroutines. Nothing really happens in
parallel, but the internal event loop switches between multiple &amp;ldquo;greenlets&amp;rdquo;
to process multiple tasks. Typically this is useful when dealing with
I/O bound operations (greenlet1 waits on one network call, greenlet2 on
another, etc). See &lt;a href=&#34;http://www.gevent.org/contents.html&#34;&gt;docs&lt;/a&gt; for more.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;javascript&#34;&gt;JavaScript&lt;/h1&gt;
&lt;p&gt;Good resources for a short, practical review of the key concepts:
[Best Frontend JS interview
questions](&lt;a href=&#34;https://performancejs.com/post/hde6d32/The-Best-Frontend-JavaScript-Interview-Questions-(Written-by-a-Frontend-Engineer)&#34;&gt;https://performancejs.com/post/hde6d32/The-Best-Frontend-JavaScript-Interview-Questions-(Written-by-a-Frontend-Engineer)&lt;/a&gt;.
To practice coding in JavaScript and improve how you use the language, I highly
recommend taking a look at &lt;a href=&#34;https://github.com/humanwhocodes/computer-science-in-javascript&#34;&gt;Computer Science in
JavaScript&lt;/a&gt;
and re-implement some of the data structures yourself.&lt;/p&gt;
&lt;h2 id=&#34;whats-a-closure&#34;&gt;What&amp;rsquo;s a closure?&lt;/h2&gt;
&lt;p&gt;Here&amp;rsquo;s a definition inspired by &amp;ldquo;Secrets of the JavaScript Ninja&amp;rdquo;, by Resig.&lt;/p&gt;
&lt;p&gt;A closure is a lexical scope created by the JavaScript engine each time a
function is created. Closures allow a function to access all the variables, as
well as other functions, that are in scope when the function itself is declared.&lt;/p&gt;
&lt;p&gt;They create a &amp;lsquo;safety bubble&amp;rsquo; containing the function and variables
that are in scope at the point of the function&amp;rsquo;s declaration. This bubble,
containing the function and its variables, stays around as long as the function
itself does.&lt;/p&gt;
&lt;h2 id=&#34;how-to-trigger-strict-mode&#34;&gt;How to trigger strict mode?&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;&#39;use strict&#39;;&lt;/code&gt;&lt;/p&gt;
&lt;h2 id=&#34;arrow-functions&#34;&gt;Arrow functions&lt;/h2&gt;
&lt;pre class=&#34;brush:javascript&#34;&gt;
    class Bar {
        constructor(name) { this.name = name; };
        getName() { return this.name; };
        delayedGetName() {
            // Correct because arrow function take `this` from their enclosing
            // context, which is, in this case, the context defined by
            // `delayedGetName`, an object method. Rad!
            setTimeout(() =&gt; this.name), 1);
        };
        incorrectDelayedGetName() {
            setTimeout(function() {
                // Incorrect because the `function` creates its own context
                return this.name;
            });
        };
    }
&lt;/pre&gt;
&lt;p&gt;Other syntaxes:&lt;/p&gt;
&lt;pre class=&#34;brush:javascript&#34;&gt;
    var log = (arg1, arg2) =&gt; { console.log(arg1, arg2); };
    var returnFirst = (arg1, arg2) =&gt; { return arg1; }
    var returnSecond = (arg1, arg2) =&gt; arg2;
    var returnsObject = (arg1, arg2) =&gt; ({data1: arg1, data2: arg2})
&lt;/pre&gt;
&lt;h2 id=&#34;value-of-this-in-different-context&#34;&gt;Value of &lt;code&gt;this&lt;/code&gt; in different context&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;this&lt;/code&gt; in a function invocation:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;global object (&lt;code&gt;window&lt;/code&gt;) in non-strict mode&lt;/li&gt;
&lt;li&gt;&lt;code&gt;undefined&lt;/code&gt; in strict mode&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;this&lt;/code&gt; in object methods: object which owns the method&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;this&lt;/code&gt; in class constructors: object being instantiated&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;this&lt;/code&gt; in bound functions: whatever it was set to be! (1s arg to &lt;code&gt;.bind&lt;/code&gt;)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;this&lt;/code&gt; in arrow functions: statically set when the arrow function is defined,
and set to be the enclosing context.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;context-binding&#34;&gt;Context binding&lt;/h2&gt;
&lt;p&gt;Calling a function with a different context:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;.call(context, arg1, arg2, ..., argN)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;.apply(context, arrayOfArgs)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Binding a function to the right context for later use:&lt;/p&gt;
&lt;pre class=&#34;brush:javascript&#34;&gt;
    class Bar {
        constructor(name) {
            this.name = name;
        };
        someMethod() { return this.name; };
    };

    var bar = new Bar(&#39;Zeitgeist&#39;);
    var getBarName = bar.someMethod;
    var boundGetBarName = bar.someMethod.bind(bar);

    getBarName() // Whoops, doesn&#39;t work!
    boundGetBarName() // Yay
&lt;/pre&gt;
&lt;h2 id=&#34;prototypes-and-inheritance-in-js&#34;&gt;Prototypes and inheritance in JS&lt;/h2&gt;
&lt;p&gt;JavaScript is a prototype-based language.&lt;/p&gt;
&lt;p&gt;Prototypes are a convenient way to define types of objects, but they&amp;rsquo;re
actually a feature of functions.&lt;/p&gt;
&lt;p&gt;Each object in JavaScript has an implicit property named &lt;code&gt;constructor&lt;/code&gt; that
references the constructor function that was used to create the object. And
because the prototype is a property of the constructor function, each object
has a way to find its prototype.&lt;/p&gt;
&lt;p&gt;Constructors are not a special feature of the language. In fact, a
&amp;ldquo;constructor&amp;rdquo; is just a function invoked in a special way (using &lt;code&gt;new&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Why is this &amp;ldquo;special way&amp;rdquo; special you ask?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Invoking a function with &lt;code&gt;new&lt;/code&gt; will call it with a context set to an empty
object.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;this&lt;/code&gt; is set to this &amp;ldquo;new&amp;rdquo; empty object implicitly created for us&lt;/li&gt;
&lt;li&gt;This &amp;ldquo;new&amp;rdquo; implicit object is given a &lt;code&gt;constructor&lt;/code&gt; property which points to
the function invoked.&lt;/li&gt;
&lt;li&gt;This &amp;ldquo;new&amp;rdquo; implicit object will be returned to the caller when that function
is done executing&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now the order of property/method resolution when calling obj.myMethod is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;instance lookup (if the property is defined on the object itself)&lt;/li&gt;
&lt;li&gt;prototype lookup. How does one lookup the &amp;ldquo;prototype&amp;rdquo; of an object? Through the object&amp;rsquo;s &lt;code&gt;constructor&lt;/code&gt; property (which points to the original constructor function). Then we look the property up in &lt;code&gt;.constructor.prototype&lt;/code&gt;, which should be an object. This is the same than &lt;code&gt;Object.getPrototypeOf(obj)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;if we haven&amp;rsquo;t found our property/method on &lt;code&gt;Object.getPrototypeOf(obj)&lt;/code&gt;, then the search continues on &lt;code&gt;Object.getPrototypeOf(Object.getPrototypeOf(obj)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;And so on and so forth until we reach a point where &lt;code&gt;Object.getPropertyOf(...)&lt;/code&gt; is &lt;code&gt;null&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A more thorough explanation with complete code samples is available at
&lt;a href=&#34;http://arnaudbrousseau.com/notes/secrets-of-the-javascript-ninja.html&#34;&gt;http://arnaudbrousseau.com/notes/secrets-of-the-javascript-ninja.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Another good article on prototypes in particular can be found at
&lt;a href=&#34;https://zeekat.nl/articles/constructors-considered-mildly-confusing.html&#34;&gt;https://zeekat.nl/articles/constructors-considered-mildly-confusing.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Inheritance with standard syntax (&lt;code&gt;Object.create&lt;/code&gt;):&lt;/p&gt;
&lt;pre class=&#34;brush:javascript&#34;&gt;
    function Animal(name) { this.name = name; }
    Animal.prototype.sleep = function() { console.log(&#39;zzz&#39;); }

    function Dog(name) { this.name = name; }
    Dog.prototype = Object.create(new Animal());
&lt;/pre&gt;
&lt;p&gt;With the ES6 &lt;code&gt;class&lt;/code&gt; syntax:&lt;/p&gt;
&lt;pre class=&#34;brush:javascript&#34;&gt;
    class Animal {
        constructor(name) { this.name = name; }
        sleep () { console.log(&#39;zzz&#39;); };
    };
    class Dog extends Animal {
        constructor(name) { this.name = name; }
        bark () { console.log(&#39;woof&#39;); }
    };
&lt;/pre&gt;
&lt;h2 id=&#34;es5-es6-vs-es7-classes&#34;&gt;ES5, ES6 vs ES7 classes&lt;/h2&gt;
&lt;p&gt;Classic:&lt;/p&gt;
&lt;pre class=&#34;brush:javascript&#34;&gt;
    function Foo(arg1) {
        this.name = arg1;
    };
    Foo.prototype.myMethod = function() {
        return this.name;
    };
    var foo = new Foo(&#39;ohhai&#39;);
&lt;/pre&gt;
&lt;p&gt;ES6 class syntax:&lt;/p&gt;
&lt;pre class=&#34;brush:javascript&#34;&gt;
    class Foo {
        constructor(arg1) {
            this.name = arg1;    
        };
        myMethod() {
            return this.name;
        };
    };
    foo = new Foo(&#39;ohhai&#39;);
&lt;/pre&gt;
&lt;h2 id=&#34;modules-in-js&#34;&gt;Modules in JS&lt;/h2&gt;
&lt;p&gt;They come in three flavors:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;AMD (RequireJS)&lt;/li&gt;
&lt;li&gt;CommonJS modules (NodeJS)&lt;/li&gt;
&lt;li&gt;ES6 modules&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&#34;brush:javascript&#34;&gt;
//------ lib.js ------
export const sqrt = Math.sqrt;
export function square(x) {
    return x * x;
}
export function diag(x, y) {
    return sqrt(square(x) + square(y));
}

//------ main.js ------
import { square, diag } from &#39;lib&#39;;
console.log(square(11)); // 121
console.log(diag(4, 3)); // 5
&lt;/pre&gt;
&lt;p&gt;See &lt;a href=&#34;http://2ality.com/2014/09/es6-modules-final.html&#34;&gt;http://2ality.com/2014/09/es6-modules-final.html&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;asynchrony-in-javascript&#34;&gt;Asynchrony in JavaScript&lt;/h2&gt;
&lt;p&gt;Three main ways to achieve this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Callbacks:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&#34;brush:javascript&#34;&gt;
    window.setTimeout(function() {
        // typical callback, called back by the browser when 10s have elapsed.
    }, 10000)
&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Promises:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&#34;brush:javascript&#34;&gt;
    var waitingPromise = new Promise(function(resolve, reject) {
        window.setTimeout(function() {
            resolve(&#39;wait is over&#39;);
        }, 10000);
    });

    waitingPromise.then(function(resolveReturnValue) {
        console.log(resolveReturnValue); // prints &#34;wait is over&#34;
    });
&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;async&lt;/code&gt;/&lt;code&gt;await&lt;/code&gt;:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&#34;brush:javascript&#34;&gt;
    var waitingPromise = new Promise(function(resolve, reject) {
        window.setTimeout(function() {
            resolve(&#39;wait is over&#39;);
        }, 10000);
    });

    // Need to be in an `async` function to be able to use `await`.
    async function wait() {
        let resolveReturnValue = await waitingPromise;
        console.log(resolveReturnValue);
    };

    wait() // waits 10s and prints &#34;wait is over&#34;
&lt;/pre&gt;
&lt;p&gt;See &lt;a href=&#34;https://blog.sessionstack.com/how-javascript-works-event-loop-and-the-rise-of-async-programming-5-ways-to-better-coding-with-2f077c4438b5&#34;&gt;this article&lt;/a&gt; on the topic.&lt;/p&gt;
&lt;h1 id=&#34;web-frontend&#34;&gt;Web Frontend&lt;/h1&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/yangshun/front-end-interview-handbook&#34;&gt;This repo&lt;/a&gt; contains
a good set of questions/answers to quickly go over a lot of the possible
frontend questions.&lt;/p&gt;
&lt;h2 id=&#34;bem&#34;&gt;BEM&lt;/h2&gt;
&lt;p&gt;BEM (&lt;b&gt;B&lt;/b&gt;lock &lt;b&gt;E&lt;/b&gt;lement &lt;b&gt;M&lt;/b&gt;odifier) is the name for a convention in CSS class names.&lt;/p&gt;
&lt;pre class=&#34;brush:css&#34;&gt;
    /** &#34;blocks&#34; are building blocks of a page (reviews, search, sidebar, etc) **/
    .block {...}
    /** &#34;elements&#34; are elements within a given block. Input element, header, etc. **/
    .block__elem {...}
    /** &#34;modifiers&#34; are things like &#34;hidden&#34; or &#34;active&#34; **/
    .block__elem--modifier {...}
&lt;/pre&gt;
&lt;p&gt;Full reference at &lt;a href=&#34;http://getbem.com/naming/&#34;&gt;http://getbem.com/naming/&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;react&#34;&gt;React&lt;/h2&gt;
&lt;p&gt;Follow &lt;a href=&#34;https://reactjs.org/tutorial/tutorial.html&#34;&gt;this tutorial&lt;/a&gt; if you&amp;rsquo;re
not familiar with React. What you need to know as a full-stack developer is
what React is and what problems it solves.&lt;/p&gt;
&lt;p&gt;React fundamentally changes the game because it introduces the concept of a &lt;strong&gt;virtual DOM&lt;/strong&gt; such that interactions between an app&amp;rsquo;s JS code and the DOM are indirect. This brings a ton of exciting possibilities such as full control over which modifications are persisted, ability to get the state of an app without relying on browser APIs, and optimal scheduling of DOM updates to avoid skipping frames.&lt;/p&gt;
&lt;h2 id=&#34;positioning-css-grids-tables-floats&#34;&gt;Positioning: CSS grids, tables, floats&lt;/h2&gt;
&lt;p&gt;Not going to get into a lot of details here but it&amp;rsquo;s good to know that in order of preference:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://css-tricks.com/snippets/css/complete-guide-grid/&#34;&gt;CSS grids&lt;/a&gt; are the hot new thing&lt;/li&gt;
&lt;li&gt;float-based layouts (or custom grid systems) are what&amp;rsquo;s realistic in the wild&lt;/li&gt;
&lt;li&gt;table-based layouts are things from the past, but probably the easiest to put together&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;svg&#34;&gt;SVG&lt;/h2&gt;
&lt;p&gt;Good to know that SVGs are great alternatives to fixes sizes, especially for
things like icons. It&amp;rsquo;s also nice to know that SVG is nothing but text and very
readable (just like HTML!). See &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Getting_Started&#34;&gt;this MDN tutorial&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;script-loading&#34;&gt;Script loading&lt;/h2&gt;
&lt;p&gt;Basic: this is the most straightforward, but browsers have to stop HTML
parsing/building at that point to download and execute the script.&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    &amp;lt;script src=&#34;https://arnaudbrousseau.com/path/to/my/script&#34;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Asynchronous: the browser doesn&amp;rsquo;t halt while dowloading this script. It blocks
and executes this script when its download completes. Because of the fact that
download times are unpredictable, &lt;code&gt;async&lt;/code&gt; scripts aren&amp;rsquo;t guaranteed to run in
the order they were included on the page.&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    &amp;lt;script async src=&#34;https://arnaudbrousseau.com/path/to/my/script&#34;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Deferred: the browser doesn&amp;rsquo;t halt while downloading this script and &lt;code&gt;defer&lt;/code&gt;s
script execution until after the HTML parsing is completed, but before
&lt;code&gt;DOMContentLoaded&lt;/code&gt; fires. The order between multiple &lt;code&gt;defer&lt;/code&gt; scripts should be
respected, but all are executed after document parsing.&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    &amp;lt;script defer src=&#34;https://arnaudbrousseau.com/path/to/my/script&#34;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/pre&gt;
&lt;p&gt;&lt;a href=&#34;https://www.html5rocks.com/en/tutorials/speed/script-loading/&#34;&gt;This article&lt;/a&gt; is a reference on this topic.&lt;/p&gt;
&lt;h2 id=&#34;loading-policies&#34;&gt;Loading Policies&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Same-origin policy&lt;/strong&gt;: when a user-agent loads content via XMLHTTPRequest (XHR aka AJAX), the same-origin policy applies. You can only load resources from the same origin than the page from which the script executes on.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;JSONP, or &amp;ldquo;JSON with padding&amp;rdquo;&lt;/strong&gt;. A clever hack to let web developers go around the same-origin policy, taking advantage of the fact that &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt;s can be loaded cross-origin. Concretely:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
   &amp;lt;script src=&#34;http://other.origin/user?id=1234&amp;amp;cb=parseResp&#34;&amp;gt;
       // Response from other.origin will be
       // parseResp({&#34;name&#34;: &#34;Arnaud&#34;, &#34;id&#34;: 1234, &#34;Rank&#34;: 117});
   &amp;lt;script&amp;gt;
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;CORS, Cross-Origin Resource Sharing&lt;/strong&gt;. This is a solution to go around the same-origin policy. This is implemented with a preflight request (OPTION request) from the browser to the server behind the origin from which a resource is fetched. The server can then respond with a list of domains for which that resource is allowed. Note: &amp;ldquo;simple&amp;rdquo; requests are not subject to CORS (preflight requests aren&amp;rsquo;t performed). &amp;ldquo;Simple requests&amp;rdquo; are any POST, HEAD, GET requests with &amp;ldquo;simple&amp;rdquo; headers. &amp;ldquo;Simple headers&amp;rdquo; are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Accept=*&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Accept-Language=*&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Content-Language=*&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Content-Type=(application/x-www-form-urlencoded|multipart/form-data|text/plain&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;CORS is useful for more that XHR-fetched content! CSS fonts or WebGL textures are subject to CORS for instance.&lt;/p&gt;
&lt;h2 id=&#34;how-browsers-work&#34;&gt;How browsers work&lt;/h2&gt;
&lt;h3 id=&#34;overall&#34;&gt;Overall&lt;/h3&gt;
&lt;p&gt;See &lt;a href=&#34;https://www.html5rocks.com/en/tutorials/internals/howbrowserswork/&#34;&gt;this excellent article&lt;/a&gt;. Any web developer should read and understand this.&lt;/p&gt;
&lt;h3 id=&#34;css-engines&#34;&gt;CSS engines&lt;/h3&gt;
&lt;p&gt;I&amp;rsquo;d just expect that people know that CSS engines exist, that their purpose is to process the CSS code included on a page. See &lt;a href=&#34;https://hacks.mozilla.org/2017/08/inside-a-super-fast-css-engine-quantum-css-aka-stylo/&#34;&gt;this article&lt;/a&gt; for a more in-depth look.&lt;/p&gt;
&lt;h3 id=&#34;js-engines&#34;&gt;JS engines&lt;/h3&gt;
&lt;p&gt;It&amp;rsquo;s good to know that JS is executed by a sandboxed process called a JS
engine. Each browser has its own, hence the differences in behavior and
performance between browsers for a given site. Examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;v8 for NodeJS and Chrome&lt;/li&gt;
&lt;li&gt;SpiderMonkey for Firefox&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;the-non-technical-portion-of-a-technical-interview&#34;&gt;The non-technical portion of a technical interview&lt;/h1&gt;
&lt;h2 id=&#34;mindset&#34;&gt;Mindset&lt;/h2&gt;
&lt;p&gt;The main question to answer during an interview is: &amp;ldquo;would I want to work with
this person?&amp;rdquo;, &amp;ldquo;would I be happy to see them sit next to me next week?&amp;rdquo;, &amp;ldquo;can I
see them help me with the current projects I&amp;rsquo;m working on?&amp;rdquo;. I find this
provides a good guide for a yes/no decision.&lt;/p&gt;
&lt;h2 id=&#34;expectations&#34;&gt;Expectations&lt;/h2&gt;
&lt;p&gt;This varies with roles and levels that you hire for, but the attributes I
generally look for in engineers that I interview are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;good communication. Not too long, to the point, with a good attitude. The kind that you would want in your daily or weekly meetings&lt;/li&gt;
&lt;li&gt;positive reaction to questions and followups (not defensive)&lt;/li&gt;
&lt;li&gt;ability to see one&amp;rsquo;s own mistakes and point them out (not masking them!)&lt;/li&gt;
&lt;li&gt;ability to say &amp;ldquo;I don&amp;rsquo;t know&amp;rdquo; or &amp;ldquo;I&amp;rsquo;m not sure&amp;rdquo; when warranted&lt;/li&gt;
&lt;li&gt;mentoring/teaching: do you see them teaching you something new?&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;assessment&#34;&gt;Assessment&lt;/h2&gt;
&lt;p&gt;To try to evaluate against my expectations, here are some questions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What would you want to learn once hired here?&lt;/li&gt;
&lt;li&gt;How do you release code to production?&lt;/li&gt;
&lt;li&gt;Can you diagram the ecosystem in which the system you worked on fits?&lt;/li&gt;
&lt;li&gt;What did you admire most about the best engineers at your previous job?&lt;/li&gt;
&lt;li&gt;Design your ideal job here&lt;/li&gt;
&lt;li&gt;What was the last time you failed to do something? Can you elaborate?&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;wrapping-up&#34;&gt;Wrapping up&lt;/h1&gt;
&lt;p&gt;You made it through it all! Wow I&amp;rsquo;m impressed. Thank you so much for reading!&lt;/p&gt;
</description>
    </item>
    <item>
      <title>How to stay sane</title>
      <link>https://arnaudbrousseau.com/notes/how-to-stay-sane.html</link>
      <pubDate>Sun, 10 Jun 2018 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/how-to-stay-sane.html</guid>
      <description>&lt;p&gt;These are reading notes from &lt;a href=&#34;https://www.goodreads.com/book/show/14059029-how-to-stay-sane&#34;&gt;&amp;ldquo;How to stay sane&amp;rdquo;&lt;/a&gt;, a small handy book full of advice. It has good signal-to-noise ratio, which is rare enough in the self-help genre.&lt;/p&gt;
&lt;h2 id=&#34;how-to-stay-sane&#34;&gt;How to Stay Sane&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Self-observation&lt;/li&gt;
&lt;li&gt;Relating to others&lt;/li&gt;
&lt;li&gt;Learning/Stress&lt;/li&gt;
&lt;li&gt;Personal narrative&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;self-observation&#34;&gt;Self-observation&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;What am I feeling now?&lt;/li&gt;
&lt;li&gt;What am I thinking now?&lt;/li&gt;
&lt;li&gt;What am I doing at this moment?&lt;/li&gt;
&lt;li&gt;How am I breathing?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;==&amp;gt; keep diaries! No need to be fancy. Just quick notes and a quick star rating for each day can go a long way.&lt;/p&gt;
&lt;h2 id=&#34;relating-to-others&#34;&gt;Relating to others&lt;/h2&gt;
&lt;p&gt;Concept of &amp;ldquo;mentalization&amp;rdquo;: ability to understand our inner mental processes and explain them&lt;/p&gt;
&lt;p&gt;Exercises for couples: the daily/weekly temperature reading. Reserve 30mins to 1hr and treat this as a meeting. Topics to tackle:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Appreciation&lt;/li&gt;
&lt;li&gt;New information&lt;/li&gt;
&lt;li&gt;Questions (they don&amp;rsquo;t need answers necessarily)&lt;/li&gt;
&lt;li&gt;Complaints with recommendations for change&lt;/li&gt;
&lt;li&gt;Wishes, hopes and dreams&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;learningstress&#34;&gt;Learning/Stress&lt;/h2&gt;
&lt;p&gt;To maintain healthy brains we need to keep learning. To keep learning we need to stay at the edge (but not too far out!) of our comfort zone.&lt;/p&gt;
&lt;p&gt;Exercise: draw the comfort/uncomfort zone. At the center, things that feels completely comfortable. Then around it things that that feel occasionally okay, then draw another circle around that containing things that don&amp;rsquo;t feel comfortable, etc.&lt;/p&gt;
&lt;h2 id=&#34;personal-narrative&#34;&gt;Personal narrative&lt;/h2&gt;
&lt;p&gt;What we feel all depends on the story we tell ourselves. It&amp;rsquo;s useful to step back and become aware of our own biases.&lt;/p&gt;
&lt;h2 id=&#34;excercices&#34;&gt;Excercices&lt;/h2&gt;
&lt;h3 id=&#34;1-minute&#34;&gt;1-minute&lt;/h3&gt;
&lt;p&gt;Focus on breathing for 60s straight (quick meditation)&lt;/p&gt;
&lt;h3 id=&#34;30-minutes&#34;&gt;30-minutes&lt;/h3&gt;
&lt;p&gt;Focus on running thoughts with a pen/paper next to you. Then label each thought before jumping to the next. At the end, group thoughts together so you have an idea, in aggregate, of what your brain thinks most about. Do this weekly and you&amp;rsquo;ll have an idea of how your mental health evolves.&lt;/p&gt;
&lt;h3 id=&#34;1-2-3-4-breathing&#34;&gt;1-2-3-4 breathing&lt;/h3&gt;
&lt;p&gt;Focus on breathing, and mentally call each of the phases:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Inhale&lt;/li&gt;
&lt;li&gt;Top of in-breath&lt;/li&gt;
&lt;li&gt;Exhale&lt;/li&gt;
&lt;li&gt;Bottom of out-breath&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;genogram&#34;&gt;Genogram&lt;/h3&gt;
&lt;p&gt;Try to map your entire family with a tree. Each node is a person. Label it with:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;year of birth&lt;/li&gt;
&lt;li&gt;whether it&amp;rsquo;s a female (circle) or male (square)&lt;/li&gt;
&lt;li&gt;up to 5 adjectives describing this person&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Symbols needed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;male: square&lt;/li&gt;
&lt;li&gt;female: circle&lt;/li&gt;
&lt;li&gt;adopted: with a dotted line&lt;/li&gt;
&lt;li&gt;pregnancy: triangle&lt;/li&gt;
&lt;li&gt;miscarriage: crossed out triangle&lt;/li&gt;
&lt;li&gt;abortion: triple crossed-out triangle&lt;/li&gt;
&lt;li&gt;death: crossed-out&lt;/li&gt;
&lt;li&gt;distant relationships: dotted&lt;/li&gt;
&lt;li&gt;cut-off relationships: dotted with 2 slashes in the middle&lt;/li&gt;
&lt;li&gt;close relationships: double line&lt;/li&gt;
&lt;li&gt;violent relationships: zig-zag lines&lt;/li&gt;
&lt;li&gt;emotional abuse: wavy line&lt;/li&gt;
&lt;li&gt;&amp;ldquo;focussed on&amp;rdquo; relationships: arrow line&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Questions to ask once you have the map in front of you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What are you noticing? What are your feelings?&lt;/li&gt;
&lt;li&gt;Think about the things you wanted or didn&amp;rsquo;t want to mimic in your family. Did any of these choices impact your life? How? What are the ones still operating now?&lt;/li&gt;
&lt;li&gt;How many of these past relationships still affect your current relationships?&lt;/li&gt;
&lt;li&gt;Which family member are you most similar to? Which of their qualities do you closely identify with?&lt;/li&gt;
&lt;li&gt;Thin about the earliest messages you got from each family member. What do you think is important in life? Where have your rules for living come from? For example, how much do you feel you can reveal about yourself to other people?&lt;/li&gt;
&lt;li&gt;How is love expressed in your family? How is caring shown? What happened if someone needed extra help? How would they get support? How do you get support when you need it?&lt;/li&gt;
&lt;li&gt;How were emotions expressed in your family? How were emotions contained/repressed?&lt;/li&gt;
&lt;li&gt;How were the children treated and brought up? How were they disciplined?&lt;/li&gt;
&lt;li&gt;What is your fantasy of a happy family? How does this compare to the reality represented on the map you just drew?&lt;/li&gt;
&lt;li&gt;What did your parents get right?&lt;/li&gt;
&lt;li&gt;How have the various family members related to each other, and how has that affected your life?&lt;/li&gt;
&lt;li&gt;Look for family crisis. Is there a pattern? Have there been any complete breakdowns of contact between sibligs, for instance? Can you identify blaming patterns?&lt;/li&gt;
&lt;li&gt;What are the patterns for divorce in your parents&#39; family?&lt;/li&gt;
&lt;li&gt;Look at the patterns of the relationships between all the people on your map. Who got on? Who was engaged? Scapegoat? Outcast? Is there a culture of favouritism?&lt;/li&gt;
&lt;li&gt;Who has had mental-heath problems? Where did this come from? Illness or caused by external events? Any traumatic experience being passed down from generation to generation?&lt;/li&gt;
&lt;li&gt;Look at your own relationship between you and your mother. Look at her relationship with her own mother. Do the same for your father and his father. Look at their relationships with both their parents.&lt;/li&gt;
&lt;li&gt;What is the pattern of the relationship to authority in your family? What were your grandparents&#39; individual relationships with authority like? your parents&#39;? Yours? How have their relationships with authority impacted upon yours? Repeat this question with regard to the opposite sex, ethnic minorities, poor/rich people, etc&lt;/li&gt;
&lt;li&gt;How did the patterns you have noticed help to shape your character, your identity?&lt;/li&gt;
&lt;li&gt;What are the beliefs about the &amp;ldquo;right way&amp;rdquo; of doing things in your family? What is the right way to make small talk or embark on a romantic relationship for instance? What are the shared values, spoken or unspoken?&lt;/li&gt;
&lt;li&gt;Do you feel in debit or credit, as far as affection and attention go? Do you feel understood by or unknown to your family of origin?&lt;/li&gt;
&lt;li&gt;How were the expectations you have of relationships formed?&lt;/li&gt;
&lt;li&gt;Are there any jobs or occupations that each generation seems to take up? Any hobbies?&lt;/li&gt;
&lt;li&gt;How do the people on the genogram talk about the other people on the genogram? Have you noticed that before? How has it influenced how you talk about other people?&lt;/li&gt;
&lt;li&gt;What was it like to be with your siblings when your parents were not present? Who played that role? Were you dismissed or valued? Do you feel there is safety in numbers? Or do you feel cowed by large groups? If it is hard for you to be in a group today, can you trace where this came from by looking at your family genogram?&lt;/li&gt;
&lt;li&gt;What are the stories that the older generation frequently told the younger generation? Are you passing them on in your turn? Are there similar rhythms to the stories you tell each other? Do you tell no stories at all?&lt;/li&gt;
&lt;li&gt;How did your parents use television? Has this been passed down? Think about how food has been eaten in your family. Sitting around a table as a group? In front of TV?&lt;/li&gt;
&lt;li&gt;What has been your ancestors&#39; attitude towards religion? Has this affected you?&lt;/li&gt;
&lt;li&gt;How open or secretive has your family been? With people inside/outside the family? What is your own attitude towards secrets?&lt;/li&gt;
&lt;li&gt;What is the emotional legacy you have inherited? Which ways of believeing, behaving, thinking and feeling have you inherited from your ancestors?&lt;/li&gt;
&lt;li&gt;What has been your conditioning as to the right and wrongs ways of doing things?&lt;/li&gt;
&lt;li&gt;Was thinking more highly regarded than feeling or doing in your family? Or was being able to emote or to act given more approval? What is the legacy of this for you?&lt;/li&gt;
&lt;li&gt;What stands out as the most important (postive and negative) things you have learnt from being in your family?&lt;/li&gt;
&lt;li&gt;What are the male and female attitudes towards work in your family? Sex? Money?&lt;/li&gt;
&lt;li&gt;what part does immigration or emigration play in your family? Or staying put? How does this affect you today?&lt;/li&gt;
&lt;li&gt;How are you tackling this exercise? How do you imagine your ancestors&#39; attitude towards it?&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    <item>
      <title>onChange</title>
      <link>https://arnaudbrousseau.com/notes/onchange.html</link>
      <pubDate>Mon, 12 Feb 2018 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/onchange.html</guid>
      <description>&lt;p&gt;I recently read &lt;a href=&#34;https://www.amazon.com/Change-Management-including-featured-Leading/dp/1422158004&#34;&gt;&amp;ldquo;On
Change&amp;rdquo;&lt;/a&gt;,
a compilation of Harvard Business Review articles about change. I picked up
this book on a whim but ended up reading it with software engineering and
engineers in mind. What follows are some notes that could be useful if you want
to initiate or lead change in engineering organizations.&lt;/p&gt;
&lt;h2 id=&#34;leading-change-why-transformation-efforts-fail&#34;&gt;&amp;ldquo;Leading Change: why transformation efforts fail&amp;rdquo;&lt;/h2&gt;
&lt;p&gt;There are 8 stages that an organization needs to go through in order for a
change to become truly durable. Since most projects in engineering are
fundamentally about change, this is a perfect set of guideline for good
technical leadership.&lt;/p&gt;
&lt;h3 id=&#34;1-establish-a-sense-of-urgency&#34;&gt;1. Establish a sense of urgency&lt;/h3&gt;
&lt;p&gt;Change has to be rooted somewhere. In the software world it can be a
deprecation deadline, some new vulnerability, a shift in the partnership
landscape, a new feature released by a third-party, or some internal data about
developer velocity. Whatever it is, change starts by identifying and discussing
these facts/numbers and shaping them into potential threats or opportunities
that the business needs to react to.
A common pitfall at this stage is risk paralysis and underestimation of risk
associated with a change. Have you ever been involved in an &amp;ldquo;easy&amp;rdquo; migration
effort which lasts forever and never seems to finish?&lt;/p&gt;
&lt;h3 id=&#34;2-forming-a-powerful-guiding-coalition&#34;&gt;2. Forming a powerful guiding coalition&lt;/h3&gt;
&lt;p&gt;That&amp;rsquo;s the idea of consensus building that&amp;rsquo;s often preached by technical
leadership books and materials, so nothing new under the sun. I find the notion
of &amp;ldquo;coalition&amp;rdquo; a bit more helpful to think about than &amp;ldquo;consensus&amp;rdquo; because
&amp;ldquo;coalition&amp;rdquo; implies active help as opposed to passive &amp;ldquo;yeah sure this is fine&amp;rdquo;
agreement.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s really important to get higher-ups aware of the initiative/project. If
possible, try getting their active support.&lt;/p&gt;
&lt;h3 id=&#34;3-creating-a-vision&#34;&gt;3. Creating a vision&lt;/h3&gt;
&lt;p&gt;This is typically done with an enhancement proposal, RFC (request for comment),
a wiki page, slides, etc. Whatever format is used doesn&amp;rsquo;t matter as long as
there is a way to communicate what needs to change and how.
The simpler the better. If the vision is too complicated people will often
phase out, won&amp;rsquo;t be on board, or will tend to actively fight the change.
Technically this means aiming for simplicity (KISS).&lt;/p&gt;
&lt;h3 id=&#34;4-communicating-the-vision&#34;&gt;4. Communicating the vision&lt;/h3&gt;
&lt;p&gt;That&amp;rsquo;s the part that most engineers or technical leads who want to drive a
change most often overlook. If a large change is required, communication around
it should be loud, clear and consistent. The status should be available for
everyone to check on, higher ups should be presenting it at engineering
all-hands, etc.
Another key aspect of this phase is &amp;ldquo;dogfooding&amp;rdquo;. Have the coalition (from step
2) support the change by going through it themselves (if applicable). A major
hurdle to change arise when the people driving a change do not implement it
themselves. They then risk being considered disingenuous or hypocrite.&lt;/p&gt;
&lt;h3 id=&#34;5-empowering-others-to-act-on-the-vision&#34;&gt;5. Empowering others to act on the vision&lt;/h3&gt;
&lt;p&gt;Make sure that there is an &amp;ldquo;easy upgrade path&amp;rdquo; (whether or not the change in
question is an upgrade), and change or fix systems/processes which make it
hard for the change to happen. This sometimes involves a bit of brainstorming.
What can you do to get out of the way and empower other developers to &amp;ldquo;work for
you&amp;rdquo;? The ideal is to get to a situation where going through change is
easier than not.&lt;/p&gt;
&lt;h3 id=&#34;6-planning-for-and-creating-short-term-wins&#34;&gt;6. Planning for and creating short-term wins&lt;/h3&gt;
&lt;p&gt;Strategically reach out to potential early adopters. Plan
short-term wins to demonstrate the value of the change, and actively break down
blockers to let others go through the change more easily.
If you don&amp;rsquo;t plan for these small wins ahead of time you may never find them,
and building momentum will become more difficult.&lt;/p&gt;
&lt;h3 id=&#34;7-consolidating-improvements-and-producing-still-more-change&#34;&gt;7. Consolidating improvements and producing still more change&lt;/h3&gt;
&lt;p&gt;This is the refinement step of the previous one. The process to go from nothing
to alpha, from alpha to beta, from beta to limited availability, from limited
availability to general availability is the same: reach out, listen, break down
blockers, modify other systems, fix yours. Rince and repeat.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s very important that you don&amp;rsquo;t declare victory too soon, otherwise you lose
momentum and support from your coalition.&lt;/p&gt;
&lt;h3 id=&#34;8-institutionalizing-new-approaches&#34;&gt;8. Institutionalizing new approaches&lt;/h3&gt;
&lt;p&gt;That&amp;rsquo;s when the change is truly over. When the new, proposed way becomes the
One Way ®, and technical/process consistency is achieved. Yes! Celebration
time.&lt;/p&gt;
&lt;h2 id=&#34;leading-change-when-business-is-good&#34;&gt;&amp;ldquo;Leading change when Business is good&amp;rdquo;&lt;/h2&gt;
&lt;p&gt;Changing is easy when things are going badly. How do you change a system when
it&amp;rsquo;s running well? &lt;a href=&#34;https://en.wiktionary.org/wiki/if_it_ain%27t_broke,_don%27t_fix_it&#34;&gt;&amp;ldquo;If it ain&amp;rsquo;t broke, don&amp;rsquo;t fix
it!&amp;quot;&lt;/a&gt;&amp;ndash; in
this case, try to focus on the larger picture and see how systems fit together.
What do we want systems/processes to look like in 2/3/5/10 years? Can we align
them better?  Focus on tests, release agility, code quality, and architecture
or infrastructure simplicity.&lt;/p&gt;
&lt;h2 id=&#34;radical-change-the-quiet-way&#34;&gt;&amp;ldquo;Radical Change, the quiet way&amp;rdquo;&lt;/h2&gt;
&lt;p&gt;This focuses on the concept of &amp;ldquo;tempered radicals&amp;rdquo;. These are individual &amp;ldquo;deep&amp;rdquo;
(not in high management, essentially) inside companies who take it upon
themselves to change an aspect of their job. In engineering this happens &lt;em&gt;all
the time&lt;/em&gt;. I found that laying out how this can be done on a spectrum is
useful. At the edge of this &amp;ldquo;quiet&amp;rdquo; radical change begins true public
leadership. Below are the business-y terms from the article along with concrete
engineering examples that I&amp;rsquo;ve seen:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&amp;ldquo;Disruptive self-expression&amp;rdquo;: introduce a new code/test
pattern/library/component to see how others react, start a communication
trend (sending RFCs internally, regular private email statuses, some new way
of organizing your backlog, or even how you communicate testing strategies to
your peers). This should be common!&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Verbal jujitsu&amp;rdquo;: translated to the technical world this refers to soft
rebellion against the status quo. People who are advocate for clean testing,
good naming, some particular technology or patter, are examples of this.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Variable-term opportunism&amp;rdquo;: instead of just complaining, these developers
look for opportunities for change to happen. Example: &amp;ldquo;oh you&amp;rsquo;re touching
this file, how about refactoring this system which sucks right now?&amp;rdquo;. The
&amp;ldquo;scout&amp;rdquo; rule (&amp;ldquo;leave a source file always cleaner than you found it&amp;rdquo;) is
somewhat related to this as well.&lt;/li&gt;
&lt;li&gt;Alliance building. In the technical community these developers are often
referred to as &amp;ldquo;champions&amp;rdquo;. They want an aspect of their job to change and
they&amp;rsquo;re ready to lead the change. There begins technical leadership.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You&amp;rsquo;ll note that these methods vary in effectiveness. Small organizations
benefit a lot from more private change initiators while bigger organizations
benefit from champions the most. Startups are more likely to say &amp;ldquo;just do it&amp;rdquo;,
whereas bigger structures can be hurt from excessive &amp;ldquo;disruptive
self-expression&amp;rdquo;, which harms effectiveness as a whole because of the lack of
consistency and predictability that it brings.&lt;/p&gt;
&lt;h2 id=&#34;the-real-reason-people-wont-change&#34;&gt;&amp;ldquo;The real reason people won&amp;rsquo;t change&amp;rdquo;&lt;/h2&gt;
&lt;p&gt;This is a way to analyze why people (or you!) are resistant to a change. In
short, ask these questions, the article says:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What would you like to see changed at work, so you could be more effective,
or so work would be more satisfying?&lt;/li&gt;
&lt;li&gt;What commitment does your complaint imply?&lt;/li&gt;
&lt;li&gt;What are you doing, or not doing, to keep your commitment from being more
fully realized?&lt;/li&gt;
&lt;li&gt;Imagine doing the opposite of the undermining behavior. Do you feel any
discomfort, worry or vague fear?&lt;/li&gt;
&lt;li&gt;By engaging in this undermining behavior, what worrisome outcome are you
committed to preventing?&lt;/li&gt;
&lt;li&gt;Identify the Big Assumption: create a sentence stem that inverts the
competing commitment then fill in the blanks.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Lots of business-bullshit-type fluff huh? This idea of a &amp;ldquo;Big Assumption&amp;rdquo; is
what we sometimes call &amp;ldquo;hidden motives&amp;rdquo;. Hence the importance of identifying
people that are NOT on board with a proposed change, to address their
concerns and understand the reason they&amp;rsquo;re opposing the change. Nothing really
revelatory here.&lt;/p&gt;
&lt;h2 id=&#34;cracking-the-code-of-change&#34;&gt;&amp;ldquo;Cracking the code of change&amp;rdquo;&lt;/h2&gt;
&lt;p&gt;This talks about &amp;ldquo;theory E&amp;rdquo; changes (Economic capability) vs &amp;ldquo;theory O&amp;rdquo; changes
(Organizational capability). It states that you need both to be successful. The
direct application of this is &lt;a href=&#34;https://en.wikipedia.org/wiki/OKR&#34;&gt;OKRs&lt;/a&gt;.
Top-level objectives metrics are the &amp;ldquo;E&amp;rdquo;, top-down driven component. Then key
results and planning are the &amp;ldquo;O&amp;rdquo; component, letting engineers be free to
accomplish what&amp;rsquo;s set for them however they want.&lt;/p&gt;
&lt;h2 id=&#34;the-hard-side-of-change-management&#34;&gt;&amp;ldquo;The Hard side of change management&amp;rdquo;&lt;/h2&gt;
&lt;p&gt;This is a process to identify which change initiatives are &amp;ldquo;at risk&amp;rdquo; of
failure. Critical components of a change initiatives are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Duration (time between meeting/reviews). The shorter the better (the article
says ideally &amp;lt; 2mo, but in software it should be much more frequent!)&lt;/li&gt;
&lt;li&gt;Integrity: how skilled are people driving the change? Assessment can be by
looking at how well-established/respected the leader is, and how much time is
allocated to the change (ideally &amp;gt; 50%, which gives him/her focus and ability
to drive that change to completion)&lt;/li&gt;
&lt;li&gt;Commitment: buy-in from upper management. Does it appear in quarterly report?
Does upper management mention this change in email/updates? Do they get why
this change is important? Do developers? Ideally, all of the answers should
be yes.&lt;/li&gt;
&lt;li&gt;Effort: how much effort is this change piling on top of other people&amp;rsquo;s
workload? Ideally less than 10%. In engineering it&amp;rsquo;s often a fixed or
negative cost. Migration are typically done once, and process changes are
usually there to make things faster and more efficient. Not slower!&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;you-made-it&#34;&gt;You made it!&lt;/h2&gt;
&lt;p&gt;Thanks for reading all the way until the end. I found the experiment of reading
a business-y book quite entertaining. Half of this book was, let&amp;rsquo;s be real,
completely useless and felt over-the-top, vague, full of jargon and
non-applicable to engineering. However, the articles I highlighted resonated
somewhat and gave me some confirmation that what I perceived to be true
intuitively in engineering is true in business and everywhere else. The first
article is probably the most useful because it lays a framework to think about
change initiatives that is relevant to engineers.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>La Chevauchée des Rois Mages</title>
      <link>https://arnaudbrousseau.com/notes/chevauchee.html</link>
      <pubDate>Sun, 04 Feb 2018 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/chevauchee.html</guid>
      <description>&lt;p&gt;Going to Dijon this weekend I visited the Musée des Beaux-Arts. Not only is it
free but there are some incredible pieces exposed there. Authentic medieval
swords, weapons and armors and finely sculpted tombs of the last duke and
duchess of Burgundy.&lt;/p&gt;
&lt;p&gt;One piece struck a debate among my friends and I: &amp;ldquo;La Chevauchée des Rois
Mages&amp;rdquo;. A painting supposedly from 1460, by an anonymous painter only known as
&amp;ldquo;Maître des Déplorations de Sarnen&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;According the museum this piece is oil on wood (if you get close you can see
the 5 pieces of woods quite distinctly). Size is 128cm high by 95cm wide.&lt;/p&gt;
&lt;p&gt;Upon seeing &amp;ldquo;La Chevauchée des Rois Mages&amp;rdquo; for the first time I immediately
though &amp;ldquo;nah, can&amp;rsquo;t be that old&amp;rdquo;. Everything about it felt
contemporary. Its colors are bright. The shape of the horses, demeanor of the
monkey and body outlines of the three men feel closer to surrealism than Middle
Age or even Renaissance.&lt;/p&gt;
&lt;p&gt;I learned afterwards that this painting was restored in 2001-2004. Here&amp;rsquo;s a
&lt;a href=&#34;http://mba-collections.dijon.fr/ow4/mba/voir.xsp?id=00101-13567&amp;amp;qid=sdx_q1&amp;amp;n=3&amp;amp;e=&#34;&gt;link&lt;/a&gt;
to its official page on the Musée des Beaux-Arts&#39; website.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ve also found a picture on an old version of their website of what the
painting looked like before. I&amp;rsquo;ve put them side-by-side for easier comparison.
Colors are quite different!&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/chevauchee_restoration.jpg&#34; alt=&#34;Side-by-side of the painting before and after its restoration&#34;&gt;&lt;/p&gt;
&lt;p&gt;This of course explains part of the anachronism, but not all. Shapes were kept
the same of course! This anonymous painter in the middle of Switzerland in the
15th century was well ahead of his time!&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s a link to a &lt;a href=&#34;https://arnaudbrousseau.com/img/chevauchee_full_size.jpg&#34;&gt;full-size photo of the painting&lt;/a&gt;
that I took.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Berkeley Tech Talk on Performance</title>
      <link>https://arnaudbrousseau.com/notes/berkeley-tech-talk.html</link>
      <pubDate>Sun, 17 Sep 2017 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/berkeley-tech-talk.html</guid>
      <description>&lt;p&gt;I went to Berkeley today to talk to a group of students about performance, why
it matters, and how Yelp as a company approaches it. Since Berkeley now teaches
Computer Science in Python and Yelp uses this language extensively I decided to
focus on Python profiling, then explained tracing and how this is used at Yelp,
and concluded with a word of caution against premature optimization and lack of
user-centered performance monitoring.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s a picture of the room before the event started:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/berkeley_tech_talk.jpg&#34; alt=&#34;Room before beginning the talk&#34;&gt;&lt;/p&gt;
&lt;p&gt;It was a lot of fun to get to talk at Berkeley, thanks to the students and Yelp
for setting this up and making it happen!&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;re interested in the slides, they&amp;rsquo;re &lt;a href=&#34;https://docs.google.com/presentation/d/e/2PACX-1vTIjM9KHIOgX2m7oK5XtKKfnsd4iwYBsoBSIl7GCI1ijDRDkqV0bQWWY8wJzZ_K4rGtwpT_O4cQU9_y/pub?start=false&amp;amp;loop=false&amp;amp;delayms=3000&#34;&gt;here&lt;/a&gt;. If this link stops working, or if you want to download a PDF version for some reason, here is a &lt;a href=&#34;https://arnaudbrousseau.com/labs/berkeley-tech-talk/berkeley_tech_talk_slides.pdf&#34;&gt;link to a hosted PDF version&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;♥&lt;/p&gt;
</description>
    </item>
    <item>
      <title>shred(1)</title>
      <link>https://arnaudbrousseau.com/notes/shred.html</link>
      <pubDate>Fri, 26 May 2017 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/shred.html</guid>
      <description>&lt;p&gt;Ever wondered about &lt;code&gt;rm&lt;/code&gt; and how file recovery utilities might or might not be able to bring delete files?
I recently stumbled upon &lt;code&gt;shred&lt;/code&gt;, a Unix coreutil to lower the chance of recovery. Here&amp;rsquo;s the exciting excerpt&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Ordinarily when you remove a file (see rm invocation), the data is not actually destroyed. Only the index listing where the file is stored is destroyed, and the storage is made available for reuse. There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused.&lt;/p&gt;
&lt;p&gt;On a busy system with a nearly-full drive, space can get reused in a few seconds. But there is no way to know for sure. If you have sensitive data, you may want to be sure that recovery is not possible by actually overwriting the file with non-sensitive data.&lt;/p&gt;
&lt;p&gt;However, even after doing that, it is possible to take the disk back to a laboratory and use a lot of sensitive (and expensive) equipment to look for the faint “echoes” of the original data underneath the overwritten data. If the data has only been overwritten once, it’s not even that hard.&lt;/p&gt;
&lt;p&gt;The best way to remove something irretrievably is to destroy the media it’s on with acid, melt it down, or the like. For cheap removable media like floppy disks, this is the preferred method. However, hard drives are expensive and hard to melt, so the shred utility tries to achieve a similar effect non-destructively.&lt;/p&gt;
&lt;p&gt;This uses many overwrite passes, with the data patterns chosen to maximize the damage they do to the old data. While this will work on floppies, the patterns are designed for best effect on hard drives.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;See &lt;a href=&#34;https://www.gnu.org/software/coreutils/manual/coreutils.html#shred-invocation&#34;&gt;shred&lt;/a&gt; for the complete manual, or type &lt;code&gt;man shred&lt;/code&gt;! Checkout &lt;a href=&#34;https://www.cs.auckland.ac.nz/~pgut001/pubs/secure_del.html&#34;&gt;this paper&lt;/a&gt; if you&amp;rsquo;re into the nitty-gritty details.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>How To Boba</title>
      <link>https://arnaudbrousseau.com/notes/how-to-boba.html</link>
      <pubDate>Fri, 15 Jul 2016 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/how-to-boba.html</guid>
      <description>&lt;h2 id=&#34;tapioca-flour&#34;&gt;Tapioca Flour&lt;/h2&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/boba-tapioca-starch.jpg&#34; alt=&#34;Tapioca flour&#34;&gt;&lt;/p&gt;
&lt;p&gt;Mix it with some boiling water and some molasses to get color&amp;hellip;and you get a really sticky dough&lt;/p&gt;
&lt;h2 id=&#34;creating-bobas-piping&#34;&gt;Creating bobas: piping&lt;/h2&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/boba-forming.jpg&#34; alt=&#34;Bobas after being piped and floured&#34;&gt;&lt;/p&gt;
&lt;p&gt;Take a ziploc bag and insert the dough into it. Seal that bag and cut one corner of the ziploc bag to be able to pipe the mixture onto a parchment-paper sheet sprinkled with tapioca flour. If you&amp;rsquo;re fancy, get a proper pastry piping bag (smile)
Let dry for at least 2 hours!&lt;/p&gt;
&lt;h2 id=&#34;creating-bobas-shaping&#34;&gt;Creating bobas: shaping&lt;/h2&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/boba-forming-2.jpg&#34; alt=&#34;Shaping boba&#34;&gt;&lt;/p&gt;
&lt;p&gt;Probably the most annoying step. After letting the small balls dry, take the dough and roll into small balls. Yes, it&amp;rsquo;s time-consuming. Take your time, put your favorite TV show on while doing this.&lt;/p&gt;
&lt;h1 id=&#34;cook-the-bobas&#34;&gt;Cook the bobas&lt;/h1&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/boba-resting.jpg&#34; alt=&#34;Bobas before cooking&#34;&gt;&lt;/p&gt;
&lt;p&gt;Heat a pot of water to boiling, and put your precious bobas inside. Let them naturally bubble up to the top, then wait for another 15mins before taking them out.
Sugar &amp;lsquo;em up!
Take the cooked boba and let them sit in a simple syrup or honey for 24hrs or so.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/boba-boiling.jpg&#34; alt=&#34;Bobas after cooking&#34;&gt;&lt;/p&gt;
&lt;h1 id=&#34;its-high-time-enjoy&#34;&gt;(it&amp;rsquo;s high time!) Enjoy!&lt;/h1&gt;
&lt;p&gt;Mix your bobas with some tea (jasmine in this case), milk and ice! Put a straw, and slurp!&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/boba-drink.jpg&#34; alt=&#34;Final boba drink&#34;&gt;&lt;/p&gt;
</description>
    </item>
    <item>
      <title>VelocityConf 2015</title>
      <link>https://arnaudbrousseau.com/notes/velocityconf2015.html</link>
      <pubDate>Sun, 31 May 2015 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/velocityconf2015.html</guid>
      <description>&lt;h2 id=&#34;service-workers-the-practical-bitsbr&#34;&gt;Service Workers, The Practical Bits&lt;br&gt;★★★★☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Patrick Meenan, Google&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Slides: &lt;a href=&#34;http://www.slideshare.net/patrickmeenan/service-workers-for-performance&#34;&gt;http://www.slideshare.net/patrickmeenan/service-workers-for-performance&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;basics-about-service-workers&#34;&gt;Basics about service workers&lt;/h3&gt;
&lt;p&gt;Tutorial about service workers. Pat isn&amp;rsquo;t an expert. Real experts &amp;ndash; they wrote
the specs and/or are working on implementations &amp;ndash; Alex Russell, Jake
Archibald.&lt;/p&gt;
&lt;p&gt;Basic concept: service workers are a layer in between the browser&amp;rsquo;s resource
fetcher and the networking stack (which includes the net cache). In other
words, service workers intercept all requests issued by a page, whether it&amp;rsquo;s
fetched from the browser&amp;rsquo;s disk cache or goes out to the internet.&lt;/p&gt;
&lt;p&gt;Information captured include original URL, all request headers, and the
response when available. It even includes cross-origin requests (response
inspection depends on Cross-Origin policy.)&lt;/p&gt;
&lt;p&gt;Service workers share a programmable cache in the form of an IndexedDB.&lt;/p&gt;
&lt;p&gt;Service workers are available for HTTPS only pages&lt;/p&gt;
&lt;p&gt;Service workers are not active on first view&lt;/p&gt;
&lt;p&gt;service workers support async APIs only. They run in the background and have no
notion of &amp;ldquo;page&amp;rdquo;. From a service worker&amp;rsquo;s point-of-view, there&amp;rsquo;s only request
coming through. No page load, no after page load. That logic has to be built.&lt;/p&gt;
&lt;h3 id=&#34;how-to-use-service-workers&#34;&gt;How to use service workers?&lt;/h3&gt;
&lt;p&gt;How do you register a service worker?&lt;/p&gt;
&lt;pre class=&#34;brush:js&#34;&gt;
navigator.serviceWorker.register(serviceWorkerFile, scope)
&lt;/pre&gt;
&lt;p&gt;What do you do with it? Attach handlers:&lt;/p&gt;
&lt;pre class=&#34;brush:js&#34;&gt;
self.addEventListener(&#39;install&#39;, function(event) {
    // runs on install...
});
self.addEventListener(&#39;install&#39;, function(event) {
    // runs once the service worker is installed
});
self.addEventListener(&#39;fetch&#39;, function(event) {
    // runs on every request
});
&lt;/pre&gt;
&lt;p&gt;From @patmeenan: &amp;ldquo;In the grand scheme of developers shooting themselves in the
foot, this is a big cannon.&amp;rdquo;. For instance:&lt;/p&gt;
&lt;pre class=&#34;brush:js&#34;&gt;
// Would intercept every request and makes it return &#39;hello world&#39;. That
// includes the main HTML document!
self.addEventListener(&#39;fetch&#39;, function(event) {
    self.respondWith(new Response(&#39;Hello world&#39;));
});
&lt;/pre&gt;
&lt;p&gt;Regardless of everything else, the browser will check for an updated service worker every 24hrs.
That means your site could get busted for 24hrs. So, you need good test coverage&lt;/p&gt;
&lt;pre class=&#34;brush:js&#34;&gt;
cache.open(cacheName).then(function(cache) {
    return cache.addAll([&#39;file1&#39;, &#39;/path/to/file/2&#39;, etc]);
})
&lt;/pre&gt;
&lt;p&gt;Service workers&#39; cache is fully programmable. But that also means you have to
manually expire entry or reset them. Double-edge sword?&lt;/p&gt;
&lt;p&gt;Service workers&#39; main use case is offline, through &lt;code&gt;navigator.online&lt;/code&gt; check you
can customize what the browser returns when the network is not available.&lt;/p&gt;
&lt;p&gt;Important to note: all ES6 request/response are &lt;strong&gt;streams&lt;/strong&gt;. So you need to clone them if
you want to do something without burning your one time chance to read them.&lt;/p&gt;
&lt;h3 id=&#34;use-cases&#34;&gt;Use cases&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Set custom timeouts&lt;/strong&gt;&lt;br&gt;
Service workers let you set custom timeouts on ads, social widgets, etc. to prevent SPOFs (Single Point of Failure)&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://chrome.google.com/webstore/detail/spof-o-matic/plikhggfbplemddobondkeogomgoodeg&#34;&gt;SPOFomatic&lt;/a&gt; is a Chrome extension to detect single point of failures&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Catch DNS/CDN/Proxy failures/errors&lt;/strong&gt;&lt;br&gt;
Not only do service workers let you catch these errors by inspecting the response code for different type of assets on a page, but you can also do all kinds of cool things like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;report these errors back to the server for further analysis or graphing&lt;/li&gt;
&lt;li&gt;define custom failover strategies (backup CDN or all the way back to origin)&lt;/li&gt;
&lt;li&gt;serve a custom page&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Race CDNs&lt;/strong&gt;&lt;br&gt;
With service workers you can have one request spawn N requests, which means you could A/B test two CDNs. Might not be the best idea money-wise.
Service workers can grab the first CDN to respond so that your CDNs are constantly &amp;ldquo;racing&amp;rdquo; one another.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Stale-While-Revalidate implementation&lt;/strong&gt;&lt;br&gt;
With service workers you can go beyond the normal expire headers and prevent
your users from reaching out to the server. For instance, instead of waiting
for a full request, serve a stale version of the asset and in parallel, check
if a fresher version is available. If it is, update the cache! If not, you&amp;rsquo;ve
just saved your user the latency of a round-trip. w00t.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Prefetching resources&lt;/strong&gt;&lt;br&gt;
That&amp;rsquo;s an obvious use-case. Since service workers are running in a completely
different process you can start prefetching resources without incurring delay
on the main page.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Re-writing the browser scheduler&lt;/strong&gt;&lt;br&gt;
That&amp;rsquo;s gnarly and super dangerous but can be done with service workers.  You
think that Chrome sucks when it downloads resources that are at the end of the
body early? You can choose to delay that and prioritize your fancy hero image!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Custom compression&lt;/strong&gt;&lt;br&gt;
Service workers can also be used to implement compression algorithms that don&amp;rsquo;t
ship with the browser natively. Got a new idea for a fancy new compression
algorithm? You can do it.
And that also applies for image compression! (but remember, service workers are
written in JS, that&amp;rsquo;s probably not the best place to decompress/recompress an
image!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Delta compression&lt;/strong&gt;&lt;br&gt;
Say a page issues a request for &lt;code&gt;main.js?v=3&lt;/code&gt;. A service worker can intercept that and, instead of letting the browser reach out to the internet, decide to see what&amp;rsquo;s in its cache and ask the server for the &lt;strong&gt;diff&lt;/strong&gt; between the cached version and the fresh version. That can save massive amounts of time.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Progressive JPEGs&lt;/strong&gt;&lt;br&gt;
Have your service worker ask the server just the bytes up until a certain point,
leave the connection open, and serve the rest later!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Generate images instead of downloading them&lt;/strong&gt;&lt;br&gt;
Large images like &lt;a href=&#34;http://www.webpagetest.org&#34;&gt;webpagetest.org&lt;/a&gt;&amp;rsquo;s images are
just charts. Instead of generating/serving this image from the server, a service
worker can transparently ask the server for the data to generate that image (say
a JSON blob) and generate a PNG client-side using a &lt;code&gt;canvas&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Metrics&lt;/strong&gt;&lt;br&gt;
Service workers are awesome for debugging/metrics. You can not only report the
usual perf data, but also errors cases. This gives visibility into failure modes
that you wouldn&amp;rsquo;t see otherwise.&lt;/p&gt;
&lt;p&gt;Last note: service workers can do &lt;code&gt;importScripts&lt;/code&gt;, so they&amp;rsquo;re composable. At
this point, there&amp;rsquo;s still opportunity to write the jQuery that lets you compose
service workers easily!&lt;/p&gt;
&lt;h2 id=&#34;best-practices-for-mysql-high-availabilitybr&#34;&gt;Best Practices for MySQL High Availability&lt;br&gt;★★☆☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Colin Charles, MariaDB&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;What is High availability?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;latency, throughput (performance scalability)&lt;/li&gt;
&lt;li&gt;replicas, snapshots, backups (durability)&lt;/li&gt;
&lt;li&gt;failover (clustering)&lt;/li&gt;
&lt;li&gt;redundancy (replication)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;different ways to handle replication:
what is SAN?
simple replication
master to master
Tungsten
NDB cluster, Galera Cluster&lt;/p&gt;
&lt;p&gt;Redundancy:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;geographical redundancy&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Durability:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;is it really written to disk?&lt;/li&gt;
&lt;li&gt;libeatmydata&lt;/li&gt;
&lt;li&gt;is it written in a transactional way to guarantee atomicity, crash safety, integrity?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Recovery can be long if &lt;code&gt;innodb_log_file_size&lt;/code&gt; is too large&lt;/p&gt;
&lt;p&gt;Redundancy through disk repllication&lt;/p&gt;
&lt;p&gt;How can you achieve redundancy through MySQL replication?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;statement based replicaation&lt;/li&gt;
&lt;li&gt;row based replication&lt;/li&gt;
&lt;li&gt;semi-sync replication&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Binary log, &lt;code&gt;relay log&lt;/code&gt;, &lt;code&gt;master_info_log&lt;/code&gt;, &lt;code&gt;relay_log_info_log&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Use percona toolkit to monitor replication delay&lt;/p&gt;
&lt;p&gt;Galera cluster is a plugin to handle replication in MySQL.&lt;/p&gt;
&lt;p&gt;NDBCluster: super high availability, amazing update performance, but very very expensive to run/upgrade.&lt;/p&gt;
&lt;p&gt;Deep-dive about MHA (set of perl scripts)&lt;/p&gt;
&lt;h2 id=&#34;metrics-metrics-everywhere-but-where-the-heck-do-you-startbr&#34;&gt;Metrics, metrics everywhere (but where the heck do you start?)&lt;br&gt;★★☆☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Tammy Everts &amp;amp; Cliff Crocker, SOASTA&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;@tameverts, @cliffcroker&lt;/p&gt;
&lt;p&gt;47% of consumers expect pages to load in 2 seconds or less.&lt;/p&gt;
&lt;p&gt;There is no one single metric that exists which can unite everyone.&lt;/p&gt;
&lt;p&gt;RUM, synthetic? Both!&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;RUM: works with a beacon, always on, getting better and better as
&lt;code&gt;window.performance.timings&lt;/code&gt; gets better&lt;/li&gt;
&lt;li&gt;Synthetic: automated bots measure website performance given a set path/URL&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Interesting idea: plot the conversion rate of a page or a flow against its
performance.&lt;/p&gt;
&lt;p&gt;TODO: look into Boomerang.js&lt;/p&gt;
&lt;p&gt;Navigation timing API.&lt;/p&gt;
&lt;p&gt;The usual talk about how it&amp;rsquo;s great to have that data available and look at it.
Yelp already reports this so it wasn&amp;rsquo;t that new.
it wasn&amp;rsquo;t that new.&lt;/p&gt;
&lt;p&gt;Interesting ideas related to navigation timings:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;let&amp;rsquo;s get a graph running of frontend vs. backend to set minds straight&lt;/li&gt;
&lt;li&gt;let&amp;rsquo;s expose that data for internal IPs&lt;/li&gt;
&lt;li&gt;visualize in a stacked graph (in that order):
&lt;ul&gt;
&lt;li&gt;DOMLoadingStart - NavigationStart&lt;/li&gt;
&lt;li&gt;DOMInteractive - NavigationStart&lt;/li&gt;
&lt;li&gt;DOMContentLoaded - NavigationStart
(which gives a break down of how DOM and page loads)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;resource timings
TODO: Timings-Allow-Origin header to be able to get a breakdown of Resource Timings&lt;/p&gt;
&lt;p&gt;See beyond-page-timings&lt;/p&gt;
&lt;p&gt;Degradations are worse on browse-type pages than on say&amp;hellip;checkout.&lt;/p&gt;
&lt;p&gt;Concept of conversion impact scores (how much does performance impact conversion depending on pages/flows?)&lt;/p&gt;
&lt;p&gt;Example SLA: response time measured using resource timing forom Chrome browsers
in the US should not exceed a median of 100ms or a 95th percentile of 500ms for
a population of more than 500 users in a 24hrs period.&lt;/p&gt;
&lt;h2 id=&#34;linux-performance-toolsbr&#34;&gt;Linux Performance Tools&lt;br&gt;★★★★★&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Brendan Gregg, Netflix&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;http://www.slideshare.net/brendangregg/velocity-2015-linux-perf-tools&#34;&gt;Link to Slides&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Objectives:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;recognize the Streetlight Anti-Method&lt;/li&gt;
&lt;li&gt;perform the Workload Characterization Method&lt;/li&gt;
&lt;li&gt;Perform the USE MEthod&lt;/li&gt;
&lt;li&gt;Learn how to start with the questions, before using tools&lt;/li&gt;
&lt;li&gt;Be aware of other methodologies&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;anti-methodologies&#34;&gt;Anti-methodologies&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Street light Anti-Method: using tools that are familiar to solve an unfamiliar
problem (similar to someone searching under a street light something lost in
the dark because the light is better there)&lt;/li&gt;
&lt;li&gt;Drunk Man Anti-Method: changing things at random until the problem goes away&lt;/li&gt;
&lt;li&gt;Blame Someone Else Anti-Method: self-explanatory!&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;actual-methodologies&#34;&gt;Actual Methodologies&lt;/h3&gt;
&lt;h4 id=&#34;problem-statement-method&#34;&gt;Problem Statement Method&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;What makes you think there is a performance problem?&lt;/li&gt;
&lt;li&gt;Has this system ever performed well?&lt;/li&gt;
&lt;li&gt;What has changed recently?&lt;/li&gt;
&lt;li&gt;Can the performance degradation be expressed in terms of latency or run time?&lt;/li&gt;
&lt;li&gt;Does the problem affect other people or applications (or is it just you?)&lt;/li&gt;
&lt;li&gt;What is the environment? Software, hardware, instance types? Versions? Configuration?&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;workload-characterization-method&#34;&gt;Workload Characterization Method&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Who is causing the load? PID, UID, IP address&lt;/li&gt;
&lt;li&gt;Why is the load called? code path, stack trace&lt;/li&gt;
&lt;li&gt;What is the load?IOSPS, tput, type, r/w&lt;/li&gt;
&lt;li&gt;How is the load changing over time?&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;the-use-method&#34;&gt;The USE method&lt;/h4&gt;
&lt;p&gt;For every resource, check:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;U&lt;/strong&gt;tilization (busy time)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;S&lt;/strong&gt;aturation (queue length or queued time)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;E&lt;/strong&gt;rrors&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;off-cpu-analysis&#34;&gt;Off-CPU Analysis&lt;/h4&gt;
&lt;p&gt;Try to track when your process gets off CPU and why. Very useful to detect
problems where your program is competing with another process, i/o issues, etc.&lt;/p&gt;
&lt;h4 id=&#34;cpu-profile-method&#34;&gt;CPU profile method&lt;/h4&gt;
&lt;p&gt;Take a CPU profile and understand all software in this profile that runs for
more than one percent of the time.&lt;/p&gt;
&lt;h4 id=&#34;rtfm-method&#34;&gt;RTFM Method&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;R&lt;/strong&gt;ead (&amp;quot;&lt;strong&gt;T&lt;/strong&gt;he &lt;strong&gt;F&lt;/strong&gt;*cking&amp;quot;) &lt;strong&gt;M&lt;/strong&gt;an pages, books, web search, co-workers, slides, support services, source
code, experimentation, social forums, etc.&lt;/p&gt;
&lt;h3 id=&#34;command-line-tools&#34;&gt;Command line tools&lt;/h3&gt;
&lt;h4 id=&#34;observability-tools&#34;&gt;Observability tools&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;uptime&lt;/code&gt;: gives you load average&lt;/li&gt;
&lt;li&gt;&lt;code&gt;top&lt;/code&gt;/&lt;code&gt;htop&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;atop&lt;/code&gt;: better than &lt;code&gt;top&lt;/code&gt;/&lt;code&gt;htop&lt;/code&gt; not to miss short lived processes&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ps -ef f&lt;/code&gt;. Better: &lt;code&gt;ps -eo user, sz,rzz,minflt,majflt,pcpu,args&lt;/code&gt;: custom fields!&lt;/li&gt;
&lt;li&gt;&lt;code&gt;vmstat 1&lt;/code&gt;: virtual memory statics. Gives CPU time broken down in user/system,
and break down of memory.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;iostat -x 1&lt;/code&gt;, &lt;code&gt;iostat -xmdz 1&lt;/code&gt;: workload characterization (&lt;code&gt;r/s&lt;/code&gt; is reads per
second, &lt;code&gt;w/s&lt;/code&gt; is writes per seconds, &lt;code&gt;avgqu-sz&lt;/code&gt; is average queue size, &lt;code&gt;%util&lt;/code&gt;
is percentage of utilization)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;mpstat -P ALL 1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;free -m&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sar -n DEV 1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;strace -tttT -p &amp;lt;pid&amp;gt;&lt;/code&gt;: system call tracer (&lt;code&gt;-ttt&lt;/code&gt;: time since epoch, &lt;code&gt;-T&lt;/code&gt;:
syscall time). &lt;strong&gt;WARNING&lt;/strong&gt;: &lt;code&gt;strace&lt;/code&gt; has massive overhead since it&amp;rsquo;s &lt;code&gt;ptrace&lt;/code&gt;
based. It can slow the target by more than 100x. Use with extreme caution in
prod! Tip: &lt;code&gt;strace p \&lt;/code&gt;pgrep something` 2&amp;gt;&amp;amp;1 | head -100` to limit the output.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;tcpdump -i eth0 -w /tmp/out.tcpdump&lt;/code&gt;: let&amp;rsquo;s you study packets sequences with
timestamps. It doesn&amp;rsquo;t scale well though, as soon as you want to analyze nodes
with large amounts of data flowing through them.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;netstat -s&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;nicstat 1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pidstat -t 1&lt;/code&gt;: to have process stats, e.g., by-thread, disk I/O&lt;/li&gt;
&lt;li&gt;&lt;code&gt;lsof -iTCP -sTCP:ESTABLISHED&lt;/code&gt;: to understand network interfaces and who is
talking to who in a sytem&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sar -m TCP,ETCP,DEV 1&lt;/code&gt;: &lt;code&gt;sar&lt;/code&gt; (system activity reporter) runs in archive or
live mode. It&amp;rsquo;s well designed, has logical groups, sensible output, etc.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collectl&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;dstat&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ss -mop&lt;/code&gt;, &lt;code&gt;ss -i&lt;/code&gt;: more socket statistics&lt;/li&gt;
&lt;li&gt;&lt;code&gt;iptraf&lt;/code&gt;: histogram of the network packets&lt;/li&gt;
&lt;li&gt;&lt;code&gt;iotop&lt;/code&gt;: lock device io by process&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pcstat&lt;/code&gt;: page cache residency by file (useful for Cassandra apparently)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;perf&lt;/code&gt;: (&lt;code&gt;perf\_events&lt;/code&gt;-based). Comes with &lt;code&gt;linux-tools-command&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;tiptop&lt;/code&gt;: IPC (Instruction Per Cycle) by process&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;benchmarking-tools&#34;&gt;Benchmarking tools&lt;/h4&gt;
&lt;p&gt;Benchmarks are tricky because it orders of magnitude easier to run them than to
refute them. To avoid that: run the benchmark for hours. In the meantime, run
the observability tools to confirm it&amp;rsquo;s hitting the right things.&lt;/p&gt;
&lt;p&gt;unixbench, lmbench, sysbench, perf bench&lt;/p&gt;
&lt;p&gt;fio &amp;ndash;name=seqwrite &amp;ndash;rw=write &amp;ndash;bs=&amp;hellip;..&lt;/p&gt;
&lt;p&gt;pchar (traceroute with bandwidth per hop)&lt;/p&gt;
&lt;p&gt;iperf&lt;/p&gt;
&lt;h4 id=&#34;tuning-tools&#34;&gt;Tuning tools&lt;/h4&gt;
&lt;p&gt;Tuning tools are acting on your system and modifying it. Be careful. Don&amp;rsquo;t fall
into the drunk-man anti-pattern. Don&amp;rsquo;t fiddle with params until the problem goes
away. Instead:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;ask yourself the question: what do I need to improve and why is this the right
setting to tune?&lt;/li&gt;
&lt;li&gt;hypothesis&lt;/li&gt;
&lt;li&gt;prediction&lt;/li&gt;
&lt;li&gt;tests&lt;/li&gt;
&lt;li&gt;analysis&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Different tools:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;sysctl&lt;/code&gt;, &lt;code&gt;/sys&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;nice&lt;/code&gt;, &lt;code&gt;renice&lt;/code&gt;, &lt;code&gt;taskset&lt;/code&gt;, &lt;code&gt;utimit&lt;/code&gt;, &lt;code&gt;chcpu&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;for more, see Brendan&amp;rsquo;s slides&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;static-tools&#34;&gt;Static tools&lt;/h4&gt;
&lt;p&gt;To do static performance tuning, check the static state and configuration of the
system:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;CPU types and flags&lt;/li&gt;
&lt;li&gt;CPU frequency scaling config&lt;/li&gt;
&lt;li&gt;storage devices&lt;/li&gt;
&lt;li&gt;file system capacity&lt;/li&gt;
&lt;li&gt;file system and volume configuration&lt;/li&gt;
&lt;li&gt;route table&lt;/li&gt;
&lt;li&gt;state of hardware&lt;/li&gt;
&lt;li&gt;&amp;hellip;etc&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Tools to do that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;netstat -rn&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ip route get &amp;lt;IP&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&amp;hellip;etc&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;profiling-tools&#34;&gt;Profiling tools&lt;/h4&gt;
&lt;p&gt;Built-in &lt;code&gt;perf&lt;/code&gt; is chill.&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    perf record -F 99 -ag -- sleep 30
    perf report -n --stdio
&lt;/pre&gt;
&lt;p&gt;(then use Bredan&amp;rsquo;s FlameGraph tool to turn the output into a cool flamechart)&lt;/p&gt;
&lt;h4 id=&#34;tracing&#34;&gt;Tracing&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;uprobe&lt;/code&gt;, &lt;code&gt;kprobe&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;perf&lt;/code&gt;, &lt;code&gt;ftrace&lt;/code&gt;, &lt;code&gt;eBPF&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;perf list &#39;block:\*&#39;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;eBPF is getting integrated into Linux 4.1. Exciting!&lt;/p&gt;
&lt;h2 id=&#34;better-off-bad-br-&#34;&gt;Better Off Bad &lt;br&gt; ★★★★☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Lara Bell&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This talk was about security.&lt;/p&gt;
&lt;p&gt;Our apps are full of precious things (data), we don&amp;rsquo;t want those precious things to get stolen.&lt;/p&gt;
&lt;p&gt;We all liars, cheats and thieves deep inside. The difference between us and real
bad guys is we don&amp;rsquo;t mean harm.&lt;/p&gt;
&lt;p&gt;Security is hard because breaking a box is against our nature. We&amp;rsquo;d rather build
stuff than destroy. We also feel cheated on if an attack is not sophisticated or
elegant. Spoiler alert: most of them aren&amp;rsquo;t!!&lt;/p&gt;
&lt;p&gt;Three steps to start at your company:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Think like a villain: be objective, keep your eyes on the prize. Hackers aren&amp;rsquo;t here for the box. They&amp;rsquo;re after what&amp;rsquo;s inside.&lt;/li&gt;
&lt;li&gt;Create a safe place to create a little chaos in, to be creative&lt;/li&gt;
&lt;li&gt;Don&amp;rsquo;t be afraid to play like you never read the rulebook (fear stop us from learning)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Challenge: mentally plan what would be the worse thing to steal/break in your
organization. How would you steal it?&lt;/p&gt;
&lt;h2 id=&#34;lessons-learned-for-large-scale-apps-running-in-a-hybrid-cloud-environmentbr&#34;&gt;Lessons learned for large-scale apps running in a hybrid cloud environment&lt;br&gt;★★★☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Dana Quinn, Intuit&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Why the cloud? Move quickly, speed up innovation.&lt;/p&gt;
&lt;p&gt;How do you get to the cloud?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Choose things that are non-prod but mission critical like build environments and load test generation&lt;/li&gt;
&lt;li&gt;Select decoupled systems (system that don&amp;rsquo;t interact with data that much, and that are okay being 15ms away)&lt;/li&gt;
&lt;li&gt;Try On-demand dev environment&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Don&amp;rsquo;t make your cloud feel like fog!&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;don&amp;rsquo;t bring legacy management patters into your cloud environments&lt;/li&gt;
&lt;li&gt;insist on the right patterns as you move to the cloud!&lt;/li&gt;
&lt;li&gt;you&amp;rsquo;ll track new metrics &amp;ndash; average instance age (keep low), utilization&lt;/li&gt;
&lt;li&gt;anti-patterns to watch for when moving from legacy: manual steps in instance setup&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Track your costs!&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;you can save money&lt;/li&gt;
&lt;li&gt;you can also waste money if your engineers aren&amp;rsquo;t used to tracking their spendings&lt;/li&gt;
&lt;li&gt;remember to shut the cloud off!&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;building-a-faster-highly-available-data-tier-for-active-workloadsbr&#34;&gt;Building a faster, highly available data tier for active workloads&lt;br&gt;★☆☆☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Dave McCrory, Basho&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Trend: &amp;ldquo;Scale or fail!&amp;rdquo;. The amount of data is expected to double every two years&lt;/p&gt;
&lt;p&gt;Challenge:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;data isolation&lt;/li&gt;
&lt;li&gt;data consistency (CAP)&lt;/li&gt;
&lt;li&gt;data gravity (interacting with data creates more data)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Speaker didn&amp;rsquo;t expose any solutions. Boo!&lt;/p&gt;
&lt;h2 id=&#34;maintaining-performance-and-reliability-at-the-edge-br&#34;&gt;Maintaining performance and reliability at the edge &lt;br&gt;★★☆☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Rob Peters, Verizon&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Conway&amp;rsquo;s law: software architecture will mirror your organization.&lt;/p&gt;
&lt;p&gt;What organization do we need to solve problem X given current software?&lt;br&gt;
VS&lt;br&gt;
Given current organization, what software can we efficiently produce to solve problem X?&lt;/p&gt;
&lt;p&gt;Second part of the talk was about culture and tooling to ensure good
performance. Ended up being a bit generic like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Tools need to have an owner&lt;/li&gt;
&lt;li&gt;When you make features for your tools, be strategic&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;engineering-for-the-long-game-br&#34;&gt;Engineering for the long game &lt;br&gt;★★★★★&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Astrid Atkinson, Google&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Loosely coupled systems are very unpredictable.&lt;/p&gt;
&lt;p&gt;At Google, the Börg ecosystem rules services&#39; world. Astrid has been at Google
for 10 year and saw that system grow and evolve.&lt;/p&gt;
&lt;p&gt;Rules of the long game:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;imagine that you will be very, very successful&lt;/li&gt;
&lt;li&gt;complexity not only increases over time. It increases with failure, success and growth. You&amp;rsquo;ll have to manage complexity somehow.&lt;/li&gt;
&lt;li&gt;good teams and people are the most precious (your team should outlast any single piece of code)&lt;/li&gt;
&lt;li&gt;adding scale should not have to mean adding people&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;How do systems grow?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Vertical growth: more of the same type of service, bigger, more involved
product of the same type&lt;/li&gt;
&lt;li&gt;Horizontal growth: more products, more types&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Rules to enable growth:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;manage software, NOT individual machines&lt;/li&gt;
&lt;li&gt;standardize your environment as much as possible: config file in the same place, naming conventions enforced, etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Rules to engineer for maintainability:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;keep an eye on what&amp;rsquo;s costing time. Consider cost broadly, otherwise you might just be shifting complexity around&lt;/li&gt;
&lt;li&gt;use shared infrastructure&lt;/li&gt;
&lt;li&gt;if you talk to another service: use exponential back-off, use timeouts (and do
something sensible with it!), think about failure modes. Doing something is better than doing nothing generally speaking&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Warning: if you share everything and consolidate too much, you&amp;rsquo;re sacrificing flexibility, so don&amp;rsquo;t do it too early. When do you consolidate? Pick your moment, be conservative &amp;ndash; avoid building new systems wherever possible.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Make boring infrastructure choices.&lt;/strong&gt; Those usually holds longest in time.&lt;/p&gt;
&lt;p&gt;Shared systems require coordination. It&amp;rsquo;s not enough just to build it, you have
to move existing workloads.&lt;/p&gt;
&lt;p&gt;Systems should protect themselves (Google&amp;rsquo;s DDOS attacks comes from inside!).
You don&amp;rsquo;t want to have a system where every user interacting with it has to file
a ticket either, so AUTOMATE and build defense mechanisms early.&lt;/p&gt;
&lt;p&gt;Second systems: cake or death?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Iterate early and often when you build a second system&lt;/li&gt;
&lt;li&gt;if your second system doesn&amp;rsquo;t unlock new capabilities, don&amp;rsquo;t do it. Big
changes require long lead times.&lt;/li&gt;
&lt;li&gt;move the biggest customer first to the new, second system. If that doesn&amp;rsquo;t
work, your new system won&amp;rsquo;t be a success.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Generally speaking: don&amp;rsquo;t let the weeds get higher than the garden.&lt;br&gt;
Invest in your tools, keep an eye out for complexity and time sink and &lt;strong&gt;take care of your people&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s no victory. It&amp;rsquo;s an ongoing game.&lt;/p&gt;
&lt;h2 id=&#34;not-your-parents-microsoftbr&#34;&gt;Not your Parents&#39; Microsoft&lt;br&gt;★☆☆☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Jessica DeVita, Microsoft&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Marketing talk about Azure and how Microsoft is doing &amp;ldquo;cool&amp;rdquo; things now. No
content at all. Entertaining I guess, they had some good memes in there.&lt;/p&gt;
&lt;h2 id=&#34;prevent-rather-than-fixbr&#34;&gt;Prevent rather than fix&lt;br&gt;★☆☆☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Jason Ding, Salesforce&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When you have customers of different sizes&amp;hellip;scope/plan/test/optimize.
Talk is about how you should test and plan before taking on large customers&amp;hellip;yup!
Got it. Thanks.&lt;/p&gt;
&lt;p&gt;##A practical type of Empathy&lt;br&gt;★★★☆☆
&lt;strong&gt;Indi Young&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;A broader range of ideas pop up when you solicit input from other people.&lt;/p&gt;
&lt;p&gt;How do you do this? Empathy.&lt;br&gt;
Empathy is a hot buzzword. It just means: be more sensitive.&lt;/p&gt;
&lt;p&gt;There are several kinds of empathy:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;mirrored empathy: somebody smiles at you, you automatically smile back&lt;/li&gt;
&lt;li&gt;personal distress: identifying with someone who goes through a bad moment&lt;/li&gt;
&lt;li&gt;emotional empathy: a friend tells you some good news, you feel happy! Although
really powerful, this kind of empathy is not repeatable. It either happens or
doesn&amp;rsquo;t. When it happens it&amp;rsquo;s great though!&lt;/li&gt;
&lt;li&gt;cognitive empathy: understand what went through a person&amp;rsquo;s mind and what
happened over time. You can make that happen. It&amp;rsquo;s repeatable, reliable and
has structure and viable purpose. Words are unreliable on the surface
(opinions, preference, explanation) because they vary with mood, interlocutor,
etc. Words &lt;strong&gt;are&lt;/strong&gt; reliable when it comes to reasoning, reaction and guiding
principles. If you dig beneath the surface for the reasoning, there is much
more clarity of meaning.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Instead of checking, thinking and making (usual cycle when you chew on an
engineering problem): try listening, then walking in that person&amp;rsquo;s shoes, then
let that simmer for a bit. You&amp;rsquo;ll be surprised at the number of new ideas!&lt;/p&gt;
&lt;p&gt;You have to &lt;strong&gt;listen&lt;/strong&gt; to develop empathy.&lt;/p&gt;
&lt;p&gt;Interesting idea: try to do your 1-1s on the phone to prevent fear of talking,
assumptions and immediate reactions. It&amp;rsquo;ll prevent the conversation from
steering too much.&lt;/p&gt;
&lt;p&gt;Talk by Twitter&lt;/p&gt;
&lt;h2 id=&#34;stream-processing-and-anomaly-detection-twitterbr&#34;&gt;Stream processing and anomaly detection @Twitter&lt;br&gt;★☆☆☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Arun Kejariwal and Sailesh Mittal, Twitter&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Real-time analytics: streaming or interactive? You have two different
architectures possible as a result.&lt;/p&gt;
&lt;p&gt;Real-time means different things for different people (wall-street real-time is
insane)&lt;/p&gt;
&lt;p&gt;Storm is a streaming platform for analyzing real-time data as it arrives
We already use storm at Yelp. Womp womp, wrong talk to attend :/&lt;/p&gt;
&lt;h2 id=&#34;visualizing-performance-data-in-engaging-waysbr&#34;&gt;Visualizing performance data in engaging ways&lt;br&gt;★★★☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Mark Zeman, SpeedCurve&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;We implicitly recognize and seek out patterns, textures and colors. Try to make
your visualizations more interesting!&lt;/p&gt;
&lt;p&gt;Sick demos at &lt;a href=&#34;http://lab.speedcurve.com&#34;&gt;SpeedCurve Lab&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;crafting-performance-alerting-toolsbr&#34;&gt;Crafting Performance alerting tools&lt;br&gt;★★★★☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Allison McKnight, Etsy&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Story of how Etsy added performance monitoring tools.&lt;/p&gt;
&lt;p&gt;Etsy is PHP on the backend. They monitor backend with &lt;code&gt;phptime&lt;/code&gt;, aggregate with &lt;a href=&#34;https://github.com/etsy/logster&#34;&gt;Logster&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;At first performance monitoring was done through dashboard. Dashboards are good, but they have problems:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;too many graphs&lt;/li&gt;
&lt;li&gt;people pushing code don&amp;rsquo;t have time to look at graphs&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Solution: monitoring!!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;First iteration&lt;/strong&gt;: email top 5 slowest pages. &lt;br&gt;
Cons: didn&amp;rsquo;t catch regressions on fast pages, the ones that people actually care about optimizing&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Second iteration&lt;/strong&gt;: perf regression report &lt;br&gt;
Cons: didn&amp;rsquo;t catch small/slow-creep regressions, difficult to tune, alert fatigue (which regressions are meaningful?)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Third Iteration&lt;/strong&gt;: change alerting mechanism! Instead of email, use Nagios! &lt;br&gt;
Cons: alerts were hard to read&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Fourth Iteration&lt;/strong&gt;: change format with &lt;a href=&#34;https://github.com/etsy/nagios-herald&#34;&gt;Nagios Heralds&lt;/a&gt;, to add context to Nagios alerts. Also, added relevant timing graphs to the email (past 1hr/24hrs) &lt;br&gt;
Cons: lots of false positives on downstream services affecting top level alerts
(if payment processor is slow, yes, payment flows are gonna be slow but there&amp;rsquo;s
nothing you can do about it!)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Fifth Iteration&lt;/strong&gt;: use Nagios service dependencies to cut down on non actionable alerts
Cons: why do I have to use my mouse or my email for things?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sixth Iteration&lt;/strong&gt;: Improving sleuthing tools, Graphing integrated with IRC bot (!!)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Next up&lt;/strong&gt;: alerting on perf improvements to celebrate more.&lt;/p&gt;
&lt;h2 id=&#34;maintaining-the-biggest-machine-in-the-world-with-mobile-appsbr&#34;&gt;Maintaining the biggest machine in the world with mobile apps&lt;br&gt;★★☆☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Lukasz Pater, CERN&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;What is CERN? The world&amp;rsquo;s largest reserach center for particle physics.&lt;br&gt;
Also, the place where the web was born.&lt;/p&gt;
&lt;p&gt;Large Hadon Collider, or LHC is millions of high-tech components installed in a
27km long circular tunnel.&lt;/p&gt;
&lt;p&gt;Infor EAM is used throughout the whole organization to support asset management
With 1000+ users working in the field, simple and mobile interfaces are vital.&lt;/p&gt;
&lt;p&gt;Mobile strategy?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Native &amp;ldquo;one size fits all&amp;rdquo; application: didn&amp;rsquo;t work that great because a lot
of use cases couldn&amp;rsquo;t be foreseen and it was tied to expensive hardware (the
actual phones)&lt;/li&gt;
&lt;li&gt;native applications for specific user tasks work great&lt;/li&gt;
&lt;li&gt;HTML5 web applications for everything else!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;On the backend: Infor EAP, then a middle server that does all the mobile
friendly stuff like compression, checksumming, caching, logging, web sockets,
etc.&lt;/p&gt;
&lt;p&gt;Mobile clients then make use of HTML5 features like &lt;code&gt;localStorage&lt;/code&gt; and &lt;code&gt;appcache&lt;/code&gt; to be able to function in tunnel when technicians do maintenance.&lt;/p&gt;
&lt;p&gt;Then talk steered towards how JS is not Java, and how jQuery is great. Wat. It
went downhill from there.&lt;/p&gt;
&lt;p&gt;Conclusion: HTML5 is great, let&amp;rsquo;s hope JS gets more standardized. Wow. Really.&lt;/p&gt;
&lt;h2 id=&#34;performance-for-the-next-billionbr&#34;&gt;Performance for the next billion&lt;br&gt;★★★★☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Bruce Lawson, Opera&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;How will the next billion Internet users come online? Asia, Africa.&lt;/p&gt;
&lt;p&gt;Number of people in asia: 4 billions.&lt;/p&gt;
&lt;p&gt;Indonesia is the 3rd top user of Facebook, yet they are still stuck with 2G
connections!&lt;/p&gt;
&lt;p&gt;India is also growing super fast from 400 million internet users today to 900
millions in 2018.&lt;/p&gt;
&lt;p&gt;We have more and more low end devices coming online. Those markets aren&amp;rsquo;t
dominated by iPhones and high end Android devices. Websites have to be
performant on lower end devices because that&amp;rsquo;s what Asia and Africa use and will
continue to use.&lt;/p&gt;
&lt;p&gt;Apps don&amp;rsquo;t scale in those markets. Websites are the only solution to propagate
updates faster.&lt;br&gt;
Solution: installable web apps through web manifest specification. Apple has
been doing it in a non-standard way for a long time. Now you can do it on
Android and Opera browsers.&lt;/p&gt;
&lt;p&gt;In rich nations, 1-2% of income is spent on internet connectivity.
In developing nations, up to &lt;strong&gt;10%&lt;/strong&gt; of income is spent on connectivity. We
cannot waste people&amp;rsquo;s money with large images. Instead, serve the right images
for each device! Use responsive images (&lt;code&gt;&amp;lt;picture&amp;gt;&lt;/code&gt;, &lt;code&gt;srcset&lt;/code&gt;.)&lt;/p&gt;
&lt;p&gt;Opera mini is a proxy browser used heavily in India/Africa to solve this exact
problem: get users decent access to the web. How it works? Opera renders
websites on the server, then proxies rendered websites to low-end devices.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Doesn&amp;rsquo;t matter how smart your phone is if your network is dumb&amp;rdquo;&lt;/p&gt;
&lt;h2 id=&#34;great-youre-a-software-company-now-whatbr&#34;&gt;Great. You&amp;rsquo;re a software company. Now what?&lt;br&gt;★☆☆☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Patrick Lightbody, New Relic&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Talk about Chipotle&amp;rsquo;s burrito button on the Apple Watch and how this changes
everything.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Every company is now a software company.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;History of monitoring:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;80s/90s: on the server&lt;/li&gt;
&lt;li&gt;2000s: on the apps&lt;/li&gt;
&lt;li&gt;today: on the users&lt;/li&gt;
&lt;li&gt;tomorrow: on the business&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;ldquo;Fast isn&amp;rsquo;t enough, we need to delight users.&amp;rdquo;&lt;/p&gt;
&lt;h2 id=&#34;twenty-thousand-leagues-inside-the-optical-fiberbr&#34;&gt;Twenty Thousand Leagues Inside the optical fiber&lt;br&gt;★★★☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Ariya Hidayat, Shape Security&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This talk was about the history of optical fiber.&lt;/p&gt;
&lt;p&gt;At first: talk! Sound waves.
As people are further and further away, they naturally tend to switch to visual
communication (light waves!) like semaphores, smoke signals, lighting signals.&lt;/p&gt;
&lt;p&gt;Bell invented the photophone but instead, telephone took off and radio took over
the world.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s not until the invention of Laser light that light-based communication
became popular again. Very popular. Now optical fiber is what everything runs
on. The amount of data we can send through one optical fiber is mind-boggling.&lt;/p&gt;
&lt;p&gt;How? Since Laser light is monochromatic, modulations (amplitude, frequency) are
possible, but also multiplexing (by having multiple colors sent through the same
optical fiber.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;I have seen further, it is by standing on the shoulders of giants.&amp;rdquo; &amp;ndash; Isaac
Newton.&lt;/p&gt;
&lt;h2 id=&#34;beyond-the-hype-cyclebr&#34;&gt;Beyond the Hype Cycle&lt;br&gt;★★☆☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Shane Evans, HP&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Talk about the entreprise and how HP is helping them move the needle. QA and
testing budgets have gone up from 18% to 30%. Yet a prime factor that hinders agile in enterprise is lack of testing.&lt;/p&gt;
&lt;p&gt;Unicorn, horses and mules (respectively early, mid-range and late adopters).
Mules are companies engineers hate (late adopters), yet people rely on them more
than any other company.&lt;/p&gt;
&lt;p&gt;How to move forward in enterprise?&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Build smarter automation&lt;/li&gt;
&lt;li&gt;Address the legacy&lt;/li&gt;
&lt;li&gt;Think about process and scalability&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;overcoming-the-challenges-of-image-deliverybr&#34;&gt;Overcoming the challenges of image delivery&lt;br&gt;★★★☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Mohammed Aboui-magd, Akamai&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Users demand better images. Users love images. Web pages are getting heavier and
heavier.&lt;/p&gt;
&lt;p&gt;Number of images served by Akamai per day: 0.75 trillion&lt;/p&gt;
&lt;p&gt;If you want to do it right you need a version of an image for each:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;user agent&lt;/li&gt;
&lt;li&gt;screen size&lt;/li&gt;
&lt;li&gt;connection type&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That&amp;rsquo;s A LOT of different images to pre-generate, store, manage and serve
dynamically. How do you manage that complexity?&lt;/p&gt;
&lt;p&gt;Akamai does just that. (talk ended on that, no solutions given&amp;hellip;kinda sucks.)&lt;/p&gt;
&lt;h2 id=&#34;reflections-on-mountain-moving-from-the-first-year-of-usdsbr&#34;&gt;Reflections on mountain moving, from the first year of USDS&lt;br&gt;★★★☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Mikey Deckerson, US Digital Service administrator&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Talk about bureaucracy. Bureaucracy is a word everyone hates but it&amp;rsquo;s really
just what happens when a large group of people have to take a decision that
matters. Saying &amp;ldquo;my office has no bureaucracy&amp;rdquo; is like saying &amp;ldquo;my town has no
climate&amp;rdquo;. At best, the climate doesn&amp;rsquo;t affect you, but it&amp;rsquo;s still there.&lt;/p&gt;
&lt;p&gt;Rules to deal with bureaucracy:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The simpler your message/statement the better&lt;/li&gt;
&lt;li&gt;Open data is rad because other people get to build stuff instead of you&lt;/li&gt;
&lt;li&gt;Open source is rad because you get to use other people&amp;rsquo;s stuff instead of
building it&lt;/li&gt;
&lt;li&gt;The bigger you can pitch your tent the better. Get as many stakeholders
onboard as possible. They will either be part of the solution or part of the
problem.&lt;/li&gt;
&lt;li&gt;Make it possible for people who have been part of the problems to be part of
the solution.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Closing wish: apply your human capital to healthcare, education, or energy.
Those are the things that matter.&lt;/p&gt;
&lt;h2 id=&#34;measurement-is-not-enoughbr&#34;&gt;Measurement is not enough&lt;br&gt;★☆☆☆☆&lt;/h2&gt;
&lt;p&gt;Buddy brewer, SOASTA&lt;/p&gt;
&lt;p&gt;Performance means very different things to different people.&lt;/p&gt;
&lt;p&gt;You have to find relationships between the data to establish relationship between people.&lt;/p&gt;
&lt;h2 id=&#34;recruiting-for-diversity-in-techbr&#34;&gt;Recruiting for Diversity in Tech&lt;br&gt;★★★☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Laine Campbell, Pythian&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Diversity is a goal unto itself&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;assume good intentions&lt;/li&gt;
&lt;li&gt;create a culture of forgiveness&lt;/li&gt;
&lt;li&gt;don&amp;rsquo;t be afraid to speak up, call out and engage&lt;/li&gt;
&lt;li&gt;recognize privileges and implicit biases as real&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There are two types of diversity:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Inherent diversity (nationality, religious, gender, age, sexual orientation,
race,&amp;hellip;)&lt;/li&gt;
&lt;li&gt;Aquired diversity (been to military? Which school/university?&amp;hellip;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Meritocracy is bullshit&lt;/strong&gt;. It doesn&amp;rsquo;t work because of implicit biaises. That&amp;rsquo;s
why a ridiculously small amount number of women lead open source projects.
People nominate people they&amp;rsquo;re comfortable with. They don&amp;rsquo;t make the choice of
diversity unless they&amp;rsquo;re forced or at least incentivized to.&lt;/p&gt;
&lt;p&gt;Instead, create goals, enforce and track them!&lt;/p&gt;
&lt;p&gt;Inbound recruiting is bad for diversity. Do outbound recruiting (meetups, online
groups, linkedin, &amp;hellip;)&lt;/p&gt;
&lt;p&gt;Have a code of conduct and enforce it!&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;mistakes are forgiven when intentions are good&lt;/li&gt;
&lt;li&gt;hatred, insults and anger get shut down&lt;/li&gt;
&lt;li&gt;education is encouraged&lt;/li&gt;
&lt;li&gt;don&amp;rsquo;t let individuals be isolated&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Just try it: eliminate names and pictures from applications. Anonymize online
handles and technical test results. It&amp;rsquo;ll help you build balanced and diverse
teams.&lt;/p&gt;
&lt;h2 id=&#34;reaching-everywherebr&#34;&gt;Reaching everywhere&lt;br&gt;★★★☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Tim Kadleck, Akamai&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This talk was about how Radio Free Europe responsive site was built with
performance in mind.&lt;/p&gt;
&lt;p&gt;Accessing Radio Free europe is punishable by death in certain country like
Iran.&lt;br&gt;
Our internet is &lt;strong&gt;not&lt;/strong&gt; their internet.&lt;/p&gt;
&lt;p&gt;2099KB is the average page size now. This is not acceptable when they are
accessed over very slow networks.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;The future is already here&amp;ndash;it&amp;rsquo;s just not very evenly distributed&amp;rdquo;&lt;/p&gt;
&lt;p&gt;We have to be performant by default. How? Set a performance budget.&lt;/p&gt;
&lt;p&gt;20% rule: most people don&amp;rsquo;t notice that it&amp;rsquo;s faster unless it&amp;rsquo;s at least 20%
faster.&lt;/p&gt;
&lt;p&gt;Goal set for Radio Free Europe: visually complete in less than 4000ms.&lt;/p&gt;
&lt;p&gt;Tips to feel performance as you develop:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Network throttling on your laptop&lt;/li&gt;
&lt;li&gt;Perf budget enforced at the build process&lt;/li&gt;
&lt;li&gt;display perf number for every page prominently: green for good, red for bad&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Other tools for performance:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;grunt-penthouse&lt;/code&gt; for critical CSS (&lt;code&gt;grunt-critical-css&lt;/code&gt; works too)&lt;/li&gt;
&lt;li&gt;use SVG sprites. One &lt;code&gt;&amp;lt;svg&amp;gt;&lt;/code&gt; elements and several &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt; to include icons&lt;/li&gt;
&lt;li&gt;progressive enhancement by &amp;ldquo;cutting the mustard&amp;rdquo;. If cuts the mustard, then
use &lt;code&gt;loadCSS&lt;/code&gt;, &lt;code&gt;loadJS&lt;/code&gt;. Otherwise, don&amp;rsquo;t bother! This lets you have a high
dynamic range (difference between the largest size and the smallest size)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;mobile-image-processingbr&#34;&gt;Mobile image processing&lt;br&gt;★★★★☆&lt;/h2&gt;
&lt;p&gt;Today, 1.8 billion photos per day are taken.
They also add up to 62.4% of the average webpage!&lt;/p&gt;
&lt;p&gt;We usually don&amp;rsquo;t think about it, but browsers have to perform a lot of work to
display an image:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;request&lt;/li&gt;
&lt;li&gt;decode&lt;/li&gt;
&lt;li&gt;copy to GPU&lt;/li&gt;
&lt;li&gt;display&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To decode an image, we have to reverse the process of encoding an image. How are
JPEGS encoded?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;RGB to YUV&lt;/li&gt;
&lt;li&gt;Chroma subsamplig&lt;/li&gt;
&lt;li&gt;CDT quantization&lt;/li&gt;
&lt;li&gt;Huffman encoding&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can view this on &lt;code&gt;chrome://tracing&lt;/code&gt; or in Firefox at &lt;code&gt;about:memory&lt;/code&gt;. Just capture your page loading and search
for &lt;code&gt;DecodeAndSampling&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Decoding images takes a LOT more time to do when images are too big for the
requested display size. If the size fits: 5ms. If it&amp;rsquo;s twice the size: 30ms. If
the image is six times bigger: 200-300ms!&lt;/p&gt;
&lt;p&gt;Mind your fancy hero images. Please please resize your images!&lt;/p&gt;
&lt;p&gt;Badly sized images are impacting:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;memory&lt;/li&gt;
&lt;li&gt;battery&lt;/li&gt;
&lt;li&gt;life of device&lt;/li&gt;
&lt;li&gt;CPU/GPU overhead&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Talk about chroma subsampling. What the heck is this? Interesting stuff (4:4:4
vs 4:2:2 vs 4:2:0). Basically 4 pixels can be condensed by just taking 2 samples
of color (or one) within them.&lt;/p&gt;
&lt;p&gt;IE led the charge on offloading chroma upsampling (the step that reverses subsampling) to the GPU. With this, decoding images takes less time. Still, resize images!&lt;/p&gt;
&lt;p&gt;Takeaways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Resize images&lt;/li&gt;
&lt;li&gt;use small breakpoints for large images&lt;/li&gt;
&lt;li&gt;meta viewport is your friend&lt;/li&gt;
&lt;li&gt;use 4:2:0 subsampling when possible&lt;/li&gt;
&lt;li&gt;image size divisible by 8 compress better&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;building-the-new-fast-msnbr&#34;&gt;Building the new fast MSN&lt;br&gt;★★★☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Amiya Gupta, Microsoft&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;http://1drv.ms/1JZlYLc&#34;&gt;Link to slides&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Several types of optimizations.&lt;/p&gt;
&lt;p&gt;Basic:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;domain sharding&lt;/li&gt;
&lt;li&gt;concatenation&lt;/li&gt;
&lt;li&gt;Gzip&lt;/li&gt;
&lt;li&gt;spriting&lt;/li&gt;
&lt;li&gt;etc&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Intermediate:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;async scripts&lt;/li&gt;
&lt;li&gt;DNS prefetch&lt;/li&gt;
&lt;li&gt;single jQuery URL&lt;/li&gt;
&lt;li&gt;lazy load images below the fold&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Advanced. Let&amp;rsquo;s talk about those.&lt;/p&gt;
&lt;p&gt;How Microsoft quantifies perceived performance: not speed index, not page phase
time (rate of change of pixels displayed on the screen over time)&lt;/p&gt;
&lt;p&gt;Microsoft&amp;rsquo;s approach to visual metrics:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;first render&lt;/li&gt;
&lt;li&gt;hero image render&lt;/li&gt;
&lt;li&gt;above fold render&lt;/li&gt;
&lt;li&gt;ad render&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Basically, not one number but several, to help narrow down where the regression
might be. Also, heavy use of user timing markers to identify problems. They are
displayed in the timeline view in IE&amp;rsquo;s F12 tools.&lt;/p&gt;
&lt;p&gt;Lessons learned:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;network isn&amp;rsquo;t always the bottleneck&lt;/li&gt;
&lt;li&gt;looking at the waterfall isn&amp;rsquo;t enough&lt;/li&gt;
&lt;li&gt;CPU cycles spent on repeated layout/styling operations&lt;/li&gt;
&lt;li&gt;Forced layout operations: the silent killer&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;What is a forced layout operation? How does it happen?&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Invalidate a section of the display tree through DOM or style
updates&lt;/li&gt;
&lt;li&gt;Read property under that tree when invalidated: e.g.
&lt;code&gt;clientWidth&lt;/code&gt;, &lt;code&gt;getBoundingClientRect&lt;/code&gt;, etc&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;How to fix?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;batch writes together&lt;/li&gt;
&lt;li&gt;avoid client-side inserts if they can be included server-side (client-side
templating is bad for performance. Avoid it!)&lt;/li&gt;
&lt;li&gt;execute reads before writes&lt;/li&gt;
&lt;li&gt;schedule read and write operations with &lt;code&gt;requestAnimationFrame&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;move operations into the head or outside the DOM whenever possible&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Caution! HTTP2 is coming!! With HTTP2 all of the following are anti-patterns:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;cookie-less domains&lt;/li&gt;
&lt;li&gt;CSS and JS bundling&lt;/li&gt;
&lt;li&gt;domain sharding&lt;/li&gt;
&lt;li&gt;image spriting&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;tcp-and-the-lower-bound-of-web-performancebr&#34;&gt;TCP and the lower bound of web performance&lt;br&gt;★★★★★&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;John Rauser, Pinterest&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Talk about how the web works. Very, very good talk. Nicely delivered.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;http://cdn.oreillystatic.com/en/assets/1/event/44/TCP%20and%20the%20Lower%20Bound%20of%20Web%20Performance%20Presentation.pdf&#34;&gt;Link to
Slides&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Stuart Cheshire said:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Making more bandwidth is easy&lt;/li&gt;
&lt;li&gt;Once you have bad latency, you&amp;rsquo;re stuck with it&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Let&amp;rsquo;s take the example of Seattle/New York latency. If those two cities were
linked with a single, continuous piece of optical fiber, the theoretical latency
would be 37ms.&lt;/p&gt;
&lt;p&gt;Now, what&amp;rsquo;s the actual Seattle/NYC latency? 90ms. Only a factor of 2! The point
is: we&amp;rsquo;ve already done a pretty good job at reducing latency. Latency is going
to be there no matter what we do and what protocol we use.&lt;/p&gt;
&lt;p&gt;Now, story about TCP/IP, the protocol which rules the web today.&lt;/p&gt;
&lt;p&gt;Early days of the telephone: people were connected to each other physically,
with operators operating switching. One conversation was going on in each
circuit.&lt;/p&gt;
&lt;p&gt;With a digital form of communication we switched to packet switched networks:
messages are broken down into packets, and packets of different messages can be
interleaved into the same circuit. This allows for a lot of multiplexing and a
better utilization rate of our networking infrastructure.&lt;/p&gt;
&lt;p&gt;But there&amp;rsquo;s no free lunch: for packet switched networks, you need congestion
control!&lt;/p&gt;
&lt;p&gt;RFC 793 is the initial TCP/IP RFC: reliability is implemented via ACKs, flow control is implemented through the concept of TCP window.&lt;/p&gt;
&lt;p&gt;In October 1986 a series of congestion collapses hit the ARPA net. John Nagles,
in RFC 896 describes the problem really well. Van Jacobson later on, through his
research comes up with the concept of TCP slow start.&lt;/p&gt;
&lt;p&gt;Later on, delayed ACK is proposed in RFC 813, reasoning being that immediate
ACKs are a ton of extra overhead in most cases.&lt;/p&gt;
&lt;p&gt;RFC 1122 recommends/codified both TCP slow start and delayed ACK, in 1989.&lt;/p&gt;
&lt;p&gt;With those two things in place, network latency strictly limits the throughput
of new TCP connection!&lt;/p&gt;
&lt;p&gt;Takeaways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Make sure you set your initial congestion window to more than 3&lt;/li&gt;
&lt;li&gt;Mind your cookies!&lt;/li&gt;
&lt;li&gt;Download small assets first&lt;/li&gt;
&lt;li&gt;Accept the speed of light. It&amp;rsquo;s not going away anytime soon.&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    <item>
      <title>Vim Tips</title>
      <link>https://arnaudbrousseau.com/notes/vim.html</link>
      <pubDate>Sun, 09 Feb 2014 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/vim.html</guid>
      <description>&lt;p&gt;Here are some nice tips and tricks I learned while practicing VIM at work or at
home.&lt;/p&gt;
&lt;h2 id=&#34;setting-vims-syntax-highlighter-to-a-particular-language&#34;&gt;Setting VIM&amp;rsquo;s syntax highlighter to a particular language&lt;/h2&gt;
&lt;p&gt;The answer is a single command: &lt;code&gt;setf&lt;/code&gt;&lt;br&gt;
(&lt;code&gt;setf markdown&lt;/code&gt;, &lt;code&gt;setf javascript&lt;/code&gt;, etc)&lt;/p&gt;
&lt;h2 id=&#34;look-up-docs-about-a-function-a-command-anything&#34;&gt;Look up docs about a function, a command, anything&lt;/h2&gt;
&lt;p&gt;When your cursor is on a word, press shift+K.&lt;/p&gt;
&lt;h2 id=&#34;delete-efficiently&#34;&gt;Delete efficiently&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;dtx&lt;/code&gt; =&amp;gt; __d__eletes un__t__il &lt;code&gt;x&lt;/code&gt; (NOT including character &lt;code&gt;x&lt;/code&gt;). It&amp;rsquo;s super useful to delete until the next parens. For instance: &lt;code&gt;dt)&lt;/code&gt; or &lt;code&gt;dt{&lt;/code&gt;&lt;br&gt;
&lt;code&gt;ctx&lt;/code&gt; =&amp;gt; lets you go to insert mode after deletion (__c__hange vs __d__elete)&lt;/p&gt;
&lt;h2 id=&#34;ctags&#34;&gt;Ctags&lt;/h2&gt;
&lt;p&gt;Ctags are pretty old fashioned but they work surprisingly well. I use them
mostly at work when diving into unfamiliar Python code.&lt;br&gt;
&lt;code&gt;ctrl+]&lt;/code&gt; lets you lookup a symbol, &lt;code&gt;ctrl+T&lt;/code&gt; brings you back to where you were.&lt;/p&gt;
&lt;h2 id=&#34;autocomplete&#34;&gt;Autocomplete&lt;/h2&gt;
&lt;p&gt;Vim has native autocomplete!&lt;br&gt;
&lt;code&gt;ctrl+N&lt;/code&gt; to trigger autocomplete and &lt;code&gt;ctrl+N&lt;/code&gt;/&lt;code&gt;ctrl+P&lt;/code&gt; to iterate over
suggestions. By default Vim searches the current file and opened buffers.&lt;/p&gt;
&lt;h2 id=&#34;editing-multiple-files&#34;&gt;Editing multiple files&lt;/h2&gt;
&lt;p&gt;You can start Vim and tell it to open multiple files &lt;code&gt;vim file1 file2 file2&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Better still: when inside of Vim you can tell it to edit a bunch of files.&lt;br&gt;
Let&amp;rsquo;s say I want to edit all my &lt;code&gt;.scss&lt;/code&gt; file. I&amp;rsquo;d type &lt;code&gt;:args path/to/css/files/*.scss&lt;/code&gt;. Magic! Now I can do edits, and type &lt;code&gt;:wnext&lt;/code&gt; to save
and switch to the next file in the list. I can also type &lt;code&gt;:args&lt;/code&gt; to see which
files have/have not been edited yet.&lt;/p&gt;
&lt;p&gt;Last tip about this: &lt;code&gt;vim -p path/to/css/files/*.scss&lt;/code&gt; will open a Vim session
with all &lt;code&gt;.scss&lt;/code&gt; files, each one opened in a different tab. How awesome is
that.&lt;/p&gt;
&lt;h2 id=&#34;greping-in-the-current-directory&#34;&gt;&lt;code&gt;grep&lt;/code&gt;ing in the current directory&lt;/h2&gt;
&lt;p&gt;One way to &lt;code&gt;grep&lt;/code&gt; for things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In Vim, press &lt;code&gt;Ctrl+z&lt;/code&gt; to go to bash&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git grep TERM&lt;/code&gt; or &lt;code&gt;grep -R TERM .&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Select for name of file&lt;/li&gt;
&lt;li&gt;&lt;code&gt;fg&lt;/code&gt; to come back to Vim&lt;/li&gt;
&lt;li&gt;&lt;code&gt;:tabe &amp;lt;filename&amp;gt;&lt;/code&gt; to edit the file you&amp;rsquo;re interested&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&amp;rsquo;ve done the above for many years and it works okay, but it has a few major
disadvantages: it doesn&amp;rsquo;t bring you to the exact line that &lt;code&gt;git grep&lt;/code&gt; or &lt;code&gt;grep&lt;/code&gt;
found, and it involves using a trackpad or mouse to select filenames.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s a better way that I&amp;rsquo;ve been experimenting with lately:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In Vim: &lt;code&gt;:vim /TERM/ */**&lt;/code&gt;. &lt;code&gt;vim&lt;/code&gt; is short for &lt;code&gt;vimgrep&lt;/code&gt;. This command
populate&amp;rsquo;s vim &amp;ldquo;quickfix&amp;rdquo; list with the results of the search (we&amp;rsquo;re
searching for TERM in all files/folders of the current directory). The &lt;code&gt;j&lt;/code&gt;
flag is here to prevent &lt;code&gt;:vimgrep&lt;/code&gt; from jumping to the first occurrence of
the search (it does that by default)&lt;/li&gt;
&lt;li&gt;Then &lt;code&gt;:copen&lt;/code&gt; to open the quickfix list. I like to open it with &lt;code&gt;:vert copen 80&lt;/code&gt; so that the list appears on a separate window, and is 80 chars wide&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Bringing these altogether: &lt;code&gt;:vim /TERM/j */** | vert copen 80&lt;/code&gt;. Alias this to a
shortcut and you never have to leave Vim to &lt;code&gt;grep&lt;/code&gt; for things!&lt;/p&gt;
&lt;p&gt;Note: &lt;code&gt;:grep -r TERM .&lt;/code&gt; also works but this shuts Vim temporarily, and forces
you to press &amp;ldquo;Enter&amp;rdquo; after the search is done. I personally prefer &lt;code&gt;vimgrep&lt;/code&gt;
because it feels like you&amp;rsquo;re not exiting the editor. You can look at code the
whole time.&lt;/p&gt;
&lt;p&gt;Another thing: if your current directory contains a large amount of files,
try adding some of them to Vim&amp;rsquo;s &lt;code&gt;wildignore&lt;/code&gt; (e.g. &lt;code&gt;:set wildignore+=node_modules&lt;/code&gt;) or be more specific: &lt;code&gt;vim /TERM/j src/tests/**/* | vert copen 80&lt;/code&gt;). Otherwise &lt;code&gt;vimgrep&lt;/code&gt; will be slow.&lt;/p&gt;
&lt;h2 id=&#34;personal-vimrc&#34;&gt;Personal .vimrc&lt;/h2&gt;
&lt;p&gt;Each vim user has to have his/her personal .vimrc. I open sourced mine on
Github, over there: &lt;a href=&#34;https://github.com/ArnaudBrousseau/dotfiles/blob/master/vimrc&#34;&gt;https://github.com/ArnaudBrousseau/dotfiles/blob/master/vimrc&lt;/a&gt;&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Mobile Web Lecture At Berkeley</title>
      <link>https://arnaudbrousseau.com/notes/lecture-berkeley-2013.html</link>
      <pubDate>Fri, 15 Nov 2013 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/lecture-berkeley-2013.html</guid>
      <description>&lt;p&gt;I was given the opportunity to give a lecture to a group of Berkeley students
in November 2013:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Audience: small group of 40 grad students&lt;/li&gt;
&lt;li&gt;Speakers: &lt;a href=&#34;https://twitter.com/hyr0&#34;&gt;Jon Madden&lt;/a&gt; and I spoke, one hour each&lt;/li&gt;
&lt;li&gt;Context: guest speaker in &lt;a href=&#34;https://github.com/jblomo/webarch253&#34;&gt;Jim Blomo&amp;rsquo;s WEBARCH253&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Subject: the Mobile Web&lt;/li&gt;
&lt;li&gt;Slides: &lt;a href=&#34;https://raw.githubusercontent.com/ArnaudBrousseau/mobile-web-lecture-berkeley/master/mobile_web_berkeley.pdf&#34;&gt;go read&amp;rsquo;em!&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The experience was fantastic. I was nervous at first but it went better than I
expected. You can find the slides and some code samples for this class online:
It&amp;rsquo;s all &lt;a href=&#34;https://github.com/ArnaudBrousseau/mobile-web-lecture-berkeley&#34;&gt;on my personal Github&lt;/a&gt;!&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Creating a Browser Language</title>
      <link>https://arnaudbrousseau.com/notes/creating-a-browser-language.html</link>
      <pubDate>Wed, 23 Oct 2013 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/creating-a-browser-language.html</guid>
      <description>&lt;h2 id=&#34;context&#34;&gt;Context&lt;/h2&gt;
&lt;p&gt;During a Hackathon, a coworker and me decided to tackle the problem of creating
a new language which runs in the browser. Our end goal: be able to write script
elements in our language and have the  browser run it for us, in realtime.&lt;/p&gt;
&lt;h2 id=&#34;goals&#34;&gt;Goals&lt;/h2&gt;
&lt;p&gt;None of us is a static compiler/JIT expert so the way we went about it is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create a toy language and its toy lexer/compiler&lt;/li&gt;
&lt;li&gt;Make our toy language compile to &lt;a href=&#34;http://llvm.org/&#34;&gt;LLVM&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Use LLVM&amp;rsquo;s tools to take advantage of the JIT&lt;/li&gt;
&lt;li&gt;Run our language is Chrome (29+) thanks to &lt;a href=&#34;http://www.chromium.org/nativeclient/pnacl&#34;&gt;PNaCl&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Hackathons at Yelp last 2 days. That&amp;rsquo;s not much time. To prepare ourselves for
these 48 hours and to make them as productive as they could be, we set up our
environment first.&lt;/p&gt;
&lt;h2 id=&#34;setting-up-llvm-environment&#34;&gt;Setting up LLVM environment&lt;/h2&gt;
&lt;p&gt;I&amp;rsquo;m usually developing on a MacBoook, so I tried first to setup llvm and
friends on my local machine. Huge failure, for which I don&amp;rsquo;t have a solution
yet.&lt;/p&gt;
&lt;h3 id=&#34;on-osx&#34;&gt;On OSX&lt;/h3&gt;
&lt;p&gt;MacOSX makes you install XCode to install compiler tools like gcc or g++.
Com&amp;rsquo;on Apple, really?&lt;br&gt;
XCode also comes with some version of llvm installed. As a result executing
&lt;code&gt;locate llvm | wc -l&lt;/code&gt; yields &lt;code&gt;610&lt;/code&gt; on my machine. Basically some sort of tools
for llvm is installed with XCode and each version of the iPhone simulator, and
also macports. No idea why those were here in the first place.&lt;/p&gt;
&lt;p&gt;Since I had no idea what version of the tools I should go with I decided to go
the hard route and install everything from source in my homedir, following
instructions from the &lt;a href=&#34;http://llvm.org/docs/GettingStarted.html&#34;&gt;LLVM getting started
page&lt;/a&gt;&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    cd ~/bin/
    mkdir llvm
    cd llvm/
    svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
    cd llvm/tools/
    svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
    cd ../projects/
    svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
    svn co http://llvm.org/svn/llvm-project/test-suite/trunk test-suite
    cd ../../
    mkdir build
    cd build/
    ../llvm/configure --prefix=/Users/abrousse/bin/llvm
    make -j10
&lt;/pre&gt;
&lt;p&gt;The listing above generated lots of output, consumed lots of my CPU, and ended with an error:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    /Users/abrousse/bin/llvm/llvm/projects/compiler-rt/lib/asan/asan_malloc_mac.cc:19:10: fatal error: &#39;CoreFoundation/CFBase.h&#39; file not found
    #include &lt;CoreFoundation/CFBase.h&gt;
             ^
      COMPILE:   clang_darwin/asan_osx_dynamic/i386: /Users/abrousse/bin/llvm/llvm/projects/compiler-rt/lib/asan/asan_posix.cc
      COMPILE:   clang_darwin/asan_osx_dynamic/i386: /Users/abrousse/bin/llvm/llvm/projects/compiler-rt/lib/asan/asan_preinit.cc
      COMPILE:   clang_darwin/asan_osx_dynamic/i386: /Users/abrousse/bin/llvm/llvm/projects/compiler-rt/lib/asan/asan_report.cc
      COMPILE:   clang_darwin/asan_osx_dynamic/i386: /Users/abrousse/bin/llvm/llvm/projects/compiler-rt/lib/asan/asan_rtl.cc
      COMPILE:   clang_darwin/asan_osx_dynamic/i386: /Users/abrousse/bin/llvm/llvm/projects/compiler-rt/lib/asan/asan_stack.cc
      COMPILE:   clang_darwin/asan_osx_dynamic/i386: /Users/abrousse/bin/llvm/llvm/projects/compiler-rt/lib/asan/asan_stats.cc
    1 error generated.
    make[5]: *** [/Users/abrousse/bin/llvm/build/tools/clang/runtime/compiler-rt/clang_darwin/asan_osx_dynamic/i386/SubDir.lib__asan/asan_malloc_mac.o] Error 1
    make[5]: *** Waiting for unfinished jobs....
    make[4]: *** [BuildRuntimeLibraries] Error 2
    rm /Users/abrousse/bin/llvm/build/Debug+Asserts/lib/clang/3.4/lib/darwin/.dir
    make[3]: *** [compiler-rt/.makeall] Error 2
    make[2]: *** [all] Error 1
    make[1]: *** [clang/.makeall] Error 2
    make: *** [all] Error 1
&lt;/pre&gt;
&lt;p&gt;So, fuckit. Another dead end. I&amp;rsquo;m suspecting all revisions from clang, llvm and
other projects aren&amp;rsquo;t tested together that often. I think something to try next
would be checking out release-tagged revisions instead of the latest master
from each project. WHY THE HELL DON&amp;rsquo;T THEY HAVE SUBMODULES? That drives me
nuts.&lt;/p&gt;
&lt;h3 id=&#34;on-ubuntu&#34;&gt;On Ubuntu&lt;/h3&gt;
&lt;p&gt;Solution for me was to install things from a Ubuntu VM. Package management is
saner, and installing llvm is a piece of cake:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    sudo apt-get install llvm
&lt;/pre&gt;
&lt;p&gt;All done! Just check that the output of &lt;code&gt;llvm --version&lt;/code&gt; gives you 3.0 and
you&amp;rsquo;re good to go.&lt;/p&gt;
&lt;h3 id=&#34;back-to-osx&#34;&gt;Back to OSX&lt;/h3&gt;
&lt;p&gt;Back to OSX. I tried what&amp;rsquo;s on the &lt;a href=&#34;http://llvm.org/releases/download.html&#34;&gt;release
page&lt;/a&gt;, where they have precompiled
binaries for OSX. On my version of OSX (10.7.5), LLVM 3.3 didn&amp;rsquo;t work properly.
Building the 3.0 tools worked properly with what&amp;rsquo;s in
&lt;a href=&#34;https://github.com/bukzor/hackathon2013.7&#34;&gt;https://github.com/bukzor/hackathon2013.7&lt;/a&gt; (check out the &lt;code&gt;macosx branch&lt;/code&gt;).&lt;/p&gt;
&lt;h2 id=&#34;goals-20&#34;&gt;Goals 2.0&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;End goal: Do hypercube animation by writing a &lt;code&gt;&amp;lt;script src=&amp;quot;woot.bl&amp;quot; type=&amp;quot;application/x-bogolisp&amp;quot;&amp;gt;...&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Sub-goals:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;(optional) Chrome extension to parse and evaluate what&amp;rsquo;s in the script tags&lt;/li&gt;
&lt;li&gt;Lexer with tests &amp;ndash; converts string to tokens, also known as scanner&lt;/li&gt;
&lt;li&gt;Parser with tests &amp;ndash; converts tokens to AST&lt;/li&gt;
&lt;li&gt;Runtime/Interpreter &amp;ndash; Uses AST to run the program in the browser&lt;/li&gt;
&lt;li&gt;(optional) Compiler &amp;ndash; converts AST to asm.js&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;results&#34;&gt;Results&lt;/h2&gt;
&lt;p&gt;We worked in the open, at &lt;a href=&#34;https://github.com/bukzor/hackathon2013.7&#34;&gt;https://github.com/bukzor/hackathon2013.7&lt;/a&gt;.&lt;br&gt;
Wanna try it out? &lt;a href=&#34;http://bukzor.github.io/hackathon2013.7/&#34;&gt;http://bukzor.github.io/hackathon2013.7/&lt;/a&gt;&lt;/p&gt;
</description>
    </item>
    <item>
      <title>HTML5DevConf 2013</title>
      <link>https://arnaudbrousseau.com/notes/html5devconf2013.html</link>
      <pubDate>Wed, 23 Oct 2013 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/html5devconf2013.html</guid>
      <description>&lt;h2 id=&#34;from-grassroots-to-green-pasturesbr&#34;&gt;From Grassroots to Green Pastures&lt;br&gt;★☆☆☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Christos Georgiopoulos, Intel&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Keynote about Intel and HTML5. This seemed like a careful mix of corporate BS,
advertising Intel&amp;rsquo;s new &amp;ldquo;XDK NEW&amp;rdquo; project and getting developers psyched about
the &amp;ldquo;Era of integrated computing&amp;rdquo;. I don&amp;rsquo;t think it was particularly useful.&lt;/p&gt;
&lt;p&gt;Things he kept hammering at the audience:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;we have to invest in HTML5&lt;/li&gt;
&lt;li&gt;HTML5 has grown from being a simple dream to being a fundation for the &amp;ldquo;age of integrated computing&amp;rdquo;&lt;/li&gt;
&lt;li&gt;Intel believes in openness and is committed to keep investing in major OS efforts&lt;/li&gt;
&lt;li&gt;closing statement: &amp;ldquo;join us together and we&amp;rsquo;ll make the world a better place&amp;rdquo; (heh)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;finally-layout-in-cssbr&#34;&gt;Finally! Layout in CSS&lt;br&gt;★★★★★&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Alan Stearns, Adobe&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Talk was about some exciting CSS specs that are coming up and/or implemented already.&lt;/p&gt;
&lt;h3 id=&#34;flexbox&#34;&gt;Flexbox&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;Status: READY TO USE!&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Fun fact: I was the only one raising my hand when he asked &amp;ldquo;who&amp;rsquo;s using flexbox
in a production website?&amp;rdquo; (we use flexbox on Yelp&amp;rsquo;s mobile site) \o/&lt;/p&gt;
&lt;p&gt;Flexbox is a lot better than what we have in CSS. CSS wasn&amp;rsquo;t made to be a
layout language and flexbox is an attempt at solving that.&lt;/p&gt;
&lt;p&gt;flexbox is a one dimensional layout system. In a flex container you can:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;distribute items along the x axis -&amp;gt; flex-start, flex-end, center, space-between, spce-around&lt;/li&gt;
&lt;li&gt;inside a flex-container contained element -&amp;gt; flex-start, flex-end, center, stretch, baseline&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Flexbox gives you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;vertical centering&lt;/li&gt;
&lt;li&gt;flexing&lt;/li&gt;
&lt;li&gt;rearranging&lt;/li&gt;
&lt;li&gt;&amp;ldquo;holy grail layout&amp;rdquo;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Sample code for a &lt;strong&gt;flex container&lt;/strong&gt;:&lt;/p&gt;
&lt;pre class=&#34;brush:css&#34;&gt;
    display: flex;
    /* or display: inline-flex; */
    flex-direction: row;
    /* Other options:
    flex-direction: column;
    flex-direction: row-reverse;
    flex-direction: column-reverse;
    */
    justify-content:
    align-items: stretch;
&lt;/pre&gt;
&lt;p&gt;Any direct child of a flex container becomes a &lt;strong&gt;flex item&lt;/strong&gt;. Flex items can:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;have an &amp;ldquo;order&amp;rdquo; css property which indicates the order in which flex items
should appear&lt;/li&gt;
&lt;li&gt;have a &amp;ldquo;flex&amp;rdquo; property that indicates the ratio at which an item gets space
when extra space becomes available to its flex container&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Solutions for  vertical centering:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;align everything to center (use &lt;code&gt;align-items&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;declare &lt;code&gt;margin: auto&lt;/code&gt; on flex items. When margins are set to auto, flex
automatically adjusts the space around those items&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There&amp;rsquo;s a lot more to flexbox, this introduces only the basics.&lt;/p&gt;
&lt;h3 id=&#34;grid-layout&#34;&gt;Grid Layout&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;Status: not ready. Expect early implementations of that next year.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s a full 2D layout system. It brings:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;length/percentages&lt;/li&gt;
&lt;li&gt;based on content&lt;/li&gt;
&lt;li&gt;flexing&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can align things based on lines, space between lines, horizontally, vertically, etc.
It&amp;rsquo;s currently being spec&amp;rsquo;d.&lt;/p&gt;
&lt;h3 id=&#34;css-exclusions&#34;&gt;CSS Exclusions&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;Status: not ready. Experimental implementations in IE10, IE11&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;CSS Exclusions are solving the overlap problem.
An exclusion is a region causing the content to float around it.&lt;/p&gt;
&lt;pre class=&#34;brush:css&#34;&gt;
.exclusion {
  wrap-flow: both/start/end/clear/maximum/minimum
}
&lt;/pre&gt;
&lt;h3 id=&#34;css-shapes&#34;&gt;CSS Shapes&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;Status: Implementation in latest webkit and blink&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;CSS Shapes enable you to wrap text around all sorts of shape (circles, square, polygon)&lt;/p&gt;
&lt;p&gt;Possible shapes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;rectangle&lt;/li&gt;
&lt;li&gt;circle&lt;/li&gt;
&lt;li&gt;ellipse&lt;/li&gt;
&lt;li&gt;polygon(x1, y1, x2, y2, x3, y3, etc)&lt;/li&gt;
&lt;li&gt;shape from image url(&amp;lsquo;image.png&amp;rsquo;)&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&#34;brush:css&#34;&gt;
.circle-float:
   float:left;
   shape-outside: circle(50%, 50%, 50%);
}

.ellipse-exclusion {
  wrap-flow: both;
  shape-outside: ellipse(50%, 50%, 90%, 30%);
  shape-margin: 10px;
}
&lt;/pre&gt;
&lt;h3 id=&#34;css-regions&#34;&gt;CSS regions&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;Status: not ready. But implementation in webkit, blink, iOS7, IE10, IE11.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Allows you to specify how the content flows from one region to another.
Another name for CSS regions: CSS named flows. Basically it lets you create a
named flow and use it.&lt;/p&gt;
&lt;pre class=&#34;brush:css&#34;&gt;
article &gt; p {
  flow-into: philip;
}

article::before {
  display: block;
  height: 50vh;
  width: 50vw;
}

article::after {
  flow-from:philip;
  display:block
}
&lt;/pre&gt;
&lt;h3 id=&#34;demos&#34;&gt;Demos&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Google toolbar which puts items that don&amp;rsquo;t fit in the header in a &amp;ldquo;burger&amp;rdquo;
items triggering a dropdown. That can be done using just CSS using name
flows.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://adobe-webplatform.github.io/Demo-for-National-Geographic-Forest-Giant/browser/src/&#34;&gt;National Geographic named flow examples&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Lots of demos for flexbox: philipwalthon.github.io/solved-by-flexbox&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;memory-management-for-smooth-infinite-scrollingbr&#34;&gt;Memory management for smooth infinite-scrolling&lt;br&gt;★★☆☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Sumit Amar, Director of Engineering, EA&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The talk was about memory management in the context of (infinite) scrolling. He
makes the distinction between unnecessary memory allocation vs leaks. Leaks in
modern browsers still exists but they&amp;rsquo;re rare.&lt;/p&gt;
&lt;p&gt;This talk is about scrolling strategies: snap-in scrolling, inertia scrolling.&lt;/p&gt;
&lt;p&gt;Solutions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;view more&lt;/li&gt;
&lt;li&gt;snap-in (not ideal for vertical scrolling)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;First strategy: push the items onto a stack, remove DOM elements, push to
localStorage. Restore when the user scrolls back.&lt;/p&gt;
&lt;p&gt;Second strategy: use a range hash table:&lt;br&gt;
&lt;code&gt;{ &#39;0-1000&#39;: [&#39;http://url1&#39;, &#39;http://url2&#39;] }&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Demo: &lt;a href=&#34;http://armar.co.in/view.html&#34;&gt;http://armar.co.in/view.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;future ideas&amp;rdquo;: pooling and recycling DOM elements, using a set of elements and
translate 3d. No idea how that would work. Like at all. He was vague during the
whole talk.&lt;/p&gt;
&lt;h2 id=&#34;javascript-insightsbr&#34;&gt;JavaScript Insights&lt;br&gt;★★★★☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Ariya Hidayat, Sencha&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Ann Robson, Yammer&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Both speakers are interested in perf and tools despite very different
backgrounds and career paths.
Talk is about some opensource, powerful JS tools.&lt;/p&gt;
&lt;p&gt;3 very important tools that everyone should use:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Linter =&amp;gt; &lt;a href=&#34;http://www.jshint.com/&#34;&gt;JSHint&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Code coverage =&amp;gt; &lt;a href=&#34;http://gotwarlost.github.io/istanbul/&#34;&gt;Istanbul&lt;/a&gt;. &amp;ldquo;If you think jslint hurts your feelings, wait till you try istanbul&amp;rdquo;&lt;/li&gt;
&lt;li&gt;cyclomentic complexity =&amp;gt; JS complexity via &lt;a href=&#34;https://github.com/es-analysis/plato&#34;&gt;Plato&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Use these tools with pre-commit hooks&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;git commit -n&lt;/code&gt; to avoid git commit hooks&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;http://esprima.org/&#34;&gt;esprima&lt;/a&gt; to analyse JS syntax tree
(using &lt;code&gt;esprima.parse&lt;/code&gt;)&lt;/p&gt;
&lt;p&gt;Use strict mode to have better validation out of the box (dupe properties in
obejcts for instance)&lt;/p&gt;
&lt;p&gt;Definition of the Boolean trap:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Obfuscated choice =&amp;gt; &lt;code&gt;var volumeSlider = new Slider(false)&lt;/code&gt;
(use config object)&lt;/li&gt;
&lt;li&gt;double-negative =&amp;gt; &lt;code&gt;component.setHidden(false)&lt;/code&gt;, &lt;code&gt;filter.setCaseInsentivive(false)&lt;/code&gt;
(use &lt;code&gt;setVisible&lt;/code&gt; and &lt;code&gt;setCaseSensitive&lt;/code&gt; instead)&lt;/li&gt;
&lt;li&gt;OH =&amp;gt; &lt;code&gt;event.initKeyEvent(&#39;keypress&#39;, true, tue, true, null, false, 0, 9)&lt;/code&gt;
(you should quit)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/nzakas/eslint&#34;&gt;ESLint&lt;/a&gt; =&amp;gt; enforces style standards at the syntax tree level.&lt;/p&gt;
&lt;p&gt;Multi-layered defense:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;editor syntax validation, linting. Main feature: be fast! You don&amp;rsquo;t want to slow down code edition&lt;/li&gt;
&lt;li&gt;pre-commit hooks: validation, linting, unit tests. CONSIDER pre-push hooks for slower things&lt;/li&gt;
&lt;li&gt;CI Server: linting, testing, integration, etc&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Visualization of large codebases: &lt;a href=&#34;http://redotheweb.com/CodeFlower/&#34;&gt;code flowers&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;from in-person discussion with Ariya&lt;/em&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Let&amp;rsquo;s explore pre-push hooks at Yelp.&lt;/li&gt;
&lt;li&gt;Let&amp;rsquo;s check out &lt;a href=&#34;http://karma-runner.github.io/&#34;&gt;Karma&lt;/a&gt;. It&amp;rsquo;s a piece of
software hooking up mocha with code quality tools. &lt;a href=&#34;http://ariya.ofilabs.com/2013/10/code-coverage-of-jasmine-tests-using-istanbul-and-karma.html&#34;&gt;Article about it&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;programming-in-cssbr&#34;&gt;Programming in CSS&lt;br&gt;★★★☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Terry Ryan, Adobe&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;A few years back: very smart people told us not to use table, but to use css.
Problem: we took that too seriously and ended up with &lt;code&gt;&amp;lt;div class=&amp;quot;table-cell&amp;quot;&amp;gt;&lt;/code&gt;
instead. Should doesn&amp;rsquo;t mean &amp;ldquo;never do it&amp;rdquo; and &amp;ldquo;prefer&amp;rdquo; doesn&amp;rsquo;t mean &amp;ldquo;always do
that&amp;rdquo;. Let&amp;rsquo;s revisit some best practices.&lt;/p&gt;
&lt;p&gt;CSS is not a programming language (no var, loops, functions) =&amp;gt; CSS is
generally an unproductive use of our time. Two paths for css:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;optimize for humans (many files, easy to read)&lt;/li&gt;
&lt;li&gt;optimize for browsers (one long, hard to read stylsheet)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Discussion about resets for a while:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;(advantage) you are in control for all styles&lt;/li&gt;
&lt;li&gt;(disadvantage) you have to style &lt;em&gt;everything&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;(note: normalize.css wasn&amp;rsquo;t mention. A shame because it&amp;rsquo;s the best of both
worlds. Oh well whatever!)&lt;/p&gt;
&lt;p&gt;Discussion about class vs id, brings discussions about css specificity,
reminder that element &amp;lt; class &amp;lt; id &amp;lt; inline &amp;lt; !important. Nothing brand new.&lt;/p&gt;
&lt;p&gt;CSS smell:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;avoid magic numbers&lt;/li&gt;
&lt;li&gt;avoid qualified selectors (&amp;lsquo;li.phone-number&amp;rsquo;)&lt;/li&gt;
&lt;li&gt;avoid undoing your css (&amp;lsquo;h2 { text-shadow: &amp;hellip;}, .post h2 { text-shadow: nonw; }&#39;)&lt;/li&gt;
&lt;li&gt;avoid super-broad rules (&amp;lsquo;body {text-shadow: 2px &amp;hellip;;}&amp;rsquo; )&lt;/li&gt;
&lt;li&gt;prefer classes to ids&lt;/li&gt;
&lt;li&gt;avoid using !important to fix css&lt;/li&gt;
&lt;li&gt;prefer specific classnames&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Object Oriented css&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;remove skins from structure&lt;/li&gt;
&lt;li&gt;remove content from container&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Should you do OOCSS? Yes if you&amp;rsquo;re in a large codebase&lt;/p&gt;
&lt;p&gt;Preprocessors. Why bother?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;variables&lt;/li&gt;
&lt;li&gt;nesting&lt;/li&gt;
&lt;li&gt;functions/mixins&lt;/li&gt;
&lt;li&gt;concatenation&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The main difference between sass, stylus and less: underlying technology and
syntax. The speaker prefers sass. He went through variables, nesting, mixins,
@import. Nothing new if you&amp;rsquo;ve written scss at Yelp.&lt;br&gt;
Then inheritance through @extend, color functions, math were covered. They&amp;rsquo;re a
bit less common but you can easily read the docs. A neat reminder.&lt;/p&gt;
&lt;p&gt;Conclusion:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;be consistent&lt;/li&gt;
&lt;li&gt;be deliberate (do things for a reason)&lt;/li&gt;
&lt;li&gt;be productive (USE A PREPROCESSOR)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;technical-challenges-from-frontend-interviewsbr&#34;&gt;Technical challenges from frontend interviews&lt;br&gt;★★★☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Shawn Drost, Hack Reactor&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This one was kind of a shot in a dark. I didn&amp;rsquo;t know what to expect.  This talk
was actually about what frontend interviews are about. Can be interesting to
refine a set of questions.&lt;/p&gt;
&lt;p&gt;The class taxonomy for frontend interviews&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;browser concepts&lt;/li&gt;
&lt;li&gt;algorithms &amp;amp; data structures&lt;/li&gt;
&lt;li&gt;soft skills&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;browser-concepts&#34;&gt;Browser concepts&lt;/h3&gt;
&lt;p&gt;Top 5 questions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;what is a closure? why is it useful?&lt;/li&gt;
&lt;li&gt;what is event delegation? Bubbling?&lt;/li&gt;
&lt;li&gt;what is the box model&lt;/li&gt;
&lt;li&gt;how can you speed up page load?&lt;/li&gt;
&lt;li&gt;what are some values for the css position property? how do they work?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;More like this: &lt;a href=&#34;https://github.com/darcyclarke/Front-end-Developer-Interview-Questions&#34;&gt;https://github.com/darcyclarke/Front-end-Developer-Interview-Questions&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;algorithm-and-data-structures&#34;&gt;Algorithm and data structures:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;3/4 of the time, naive solution is an array and you should consider a hash&lt;/li&gt;
&lt;li&gt;all anagrams, all the time. Go for recursive solution, interviewers love them.
(then he talked about function, base case, step case when you call the same function)&lt;/li&gt;
&lt;li&gt;n-queens, break a dollar and variants
otherwise =&amp;gt; for&lt;a href=&#34;http://www.amazon.com/Cracking-Coding-Interview-Programming-Questions/dp/098478280X&#34;&gt;cracking the coding interview&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;soft-skills&#34;&gt;Soft skills&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;http://www.interviewcake.com/tips-and-tricks&#34;&gt;http://www.interviewcake.com/tips-and-tricks&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://docs.google.com/a/yelp.com/presentation/d/1PB7gOwRVr1Xiw9jS01bya9oDzdXe5tE7JpWk1KaZjmM/&#34;&gt;Slides for this talk&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;immersive-interaction-experiences-pointer-events-panning--zooming-and-gesturesbr&#34;&gt;Immersive Interaction Experiences: Pointer Events, Panning &amp;amp; Zooming, and Gestures&lt;br&gt;★★★★★&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Jacob Rossi, Microsoft&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Today we have devices with very very different form factors (TV, tablets,
stylus, etc.)&lt;br&gt;
Users want to make the user forget they&amp;rsquo;re touching glass. Make them feel like
they&amp;rsquo;re touching the page. It also means 60fps so that the page stays
responsive and feels &amp;ldquo;stuck&amp;rdquo; to your finger&lt;/p&gt;
&lt;p&gt;KEEP IT SIMPLE (don&amp;rsquo;t use a complex interaction models. 2 fingers swipe to open
the menu, 3 fingers swipe to search&amp;hellip;that doesn&amp;rsquo;t work)&lt;/p&gt;
&lt;p&gt;For panning and zooming, MS has come up with a really cool, industry leading
solution and that&amp;rsquo;s what&amp;rsquo;s going to be explained in this talk.&lt;/p&gt;
&lt;h3 id=&#34;snap-points&#34;&gt;Snap Points&lt;/h3&gt;
&lt;p&gt;MS submitted a spec for snap point and snap type. Example:&lt;/p&gt;
&lt;pre class=&#34;brush:css&#34;&gt;
.snap {
  overflow-x: scoll;
  -ms-scroll-snap-points-x: snapInterval(0px, 100%);
  -ms-scroll-snap-type: mandatory;
}
&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;WOW holly shit that&amp;rsquo;s a native slider!&lt;/em&gt; Let&amp;rsquo;s use this on m.yelp.com as soon
as it&amp;rsquo;s implemented in IE mobile!&lt;br&gt;
Other sample use for snap points: pull-down menus.&lt;/p&gt;
&lt;h3 id=&#34;pointer-events&#34;&gt;Pointer Events&lt;/h3&gt;
&lt;p&gt;Pointer events now have pressure, touch size, etc&amp;hellip;and those are properties of
the event. Sample events: &lt;code&gt;pointerdown&lt;/code&gt;, &lt;code&gt;pointerup&lt;/code&gt;,&lt;code&gt;pointercancel&lt;/code&gt;,
&lt;code&gt;pointermove&lt;/code&gt;, &lt;code&gt;pointerover&lt;/code&gt;, &lt;code&gt;pointerout&lt;/code&gt;, &lt;code&gt;pointerenter&lt;/code&gt;, &lt;code&gt;pointerleave&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You can be device-specific when you need it through &lt;code&gt;event.pointerType&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;touch-action: none&lt;/code&gt; is a CSS property to deactivate touch handling on an
element.  &lt;code&gt;touch-action: none&lt;/code&gt; is acting as &lt;code&gt;preventDefault&lt;/code&gt; would. There are
other values for &lt;code&gt;touch-action&lt;/code&gt; (&lt;code&gt;pan-y&lt;/code&gt;, &lt;code&gt;pan-x&lt;/code&gt;, etc).&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s important because of the performance implication. If you call
&lt;code&gt;preventDefault()&lt;/code&gt; the browser has no choice but to run JS to find out if it
must pan or zoom.&lt;br&gt;
With a CSS rule, things can be determined much faster.&lt;br&gt;
300ms delay in IE to disable double tap? Just one line of CSS!&lt;/p&gt;
&lt;p&gt;Pointer events let you handle multi touch really easily through pointer IDs
(each pointer event gets an ID corresponding to the finger it matches)&lt;br&gt;
Event properties for pointer events: &lt;code&gt;width&lt;/code&gt;, &lt;code&gt;height&lt;/code&gt;, &lt;code&gt;pressure&lt;/code&gt;, &lt;code&gt;tiltX&lt;/code&gt;,
&lt;code&gt;tiltY&lt;/code&gt;. AWESOME! Pointer events reached the candidate recommendation status.
It&amp;rsquo;s now unprefixed in IE11.&lt;/p&gt;
&lt;p&gt;Frameworks to enjoy pointer events now:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;http://handjs.codeplex.com/&#34;&gt;hands.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/Polymer/PointerEvents&#34;&gt;polymer polyfill&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/MSOpenTech/cordova-pointerevents&#34;&gt;Cordova/PhoneGap plugin&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;gesture-api&#34;&gt;Gesture API&lt;/h3&gt;
&lt;p&gt;Pointer events give you RAW stuff. If you want more abstract info: use gesture
events. To use them here are the steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Grab an element &lt;code&gt;elem.addEventListener(&amp;quot;MSGestureChange&amp;quot;, fn);&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;instantiate a gesture recognition thing &lt;code&gt;var g = new MSGesture();&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Assign target &lt;code&gt;g.target = elem;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Profit. The gesture analyzer gives you rotation, scale, translationXY,
velocity, angle, and all of those are deltas since last gesture event.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;final-advice-for-mobile&#34;&gt;Final advice for mobile&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Use hit targets that are more than 40px width and height&lt;/li&gt;
&lt;li&gt;Avoid hover menus&lt;/li&gt;
&lt;li&gt;Touch is not the same as &amp;ldquo;no mouse&amp;rdquo;&lt;/li&gt;
&lt;li&gt;Touch is not the same as mobile&lt;/li&gt;
&lt;li&gt;Use specific HTML5 input types. It&amp;rsquo;s a cheap win.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;how-cupcakes-alice-in-wonderland-and-baby-elephants-are-moving-the-web-forwardbr&#34;&gt;How cupcakes, Alice in Wonderland and baby elephants are moving the web forward&lt;br&gt;★★★☆☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Arno Gourdol, Adobe&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Arno manages the web team at Adobe. Talks about different medium and how they
came to be what they are. What makes the web different as a media?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;connected&lt;/li&gt;
&lt;li&gt;interactive&lt;/li&gt;
&lt;li&gt;malleable&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Then haha! this presentation is actually HTML AND CSS! Woo! (heh)&lt;br&gt;
=&amp;gt; &lt;a href=&#34;http://arno.org/20131023/&#34;&gt;http://arno.org/20131023/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;http://topcoat.io&#34;&gt;http://topcoat.io&lt;/a&gt; is a skin for webapps components (brief demo)&lt;/p&gt;
&lt;p&gt;SVG:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;resolution independence&lt;/li&gt;
&lt;li&gt;fewer http request&lt;/li&gt;
&lt;li&gt;dom based, scriptable&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Announcement: snap.svg released. Looks like sort of what jQuery is to JavaScript&lt;/p&gt;
&lt;p&gt;From there, several demos follow, demonstrating animations in SVG. Pretty cool
demos for the most part. &lt;a href=&#34;http://snapsvg.io&#34;&gt;http://snapsvg.io&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Demo:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;http://adobe-webplatform.github.io/Demo-for-National-Geographic-Forest-Giant/browser/src/&#34;&gt;National Geographic named flow examples&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://adobe-webplatform.github.io/Demo-for-Alice-s-Adventures-in-Wonderland/&#34;&gt;Alice in Wonderland&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;a chrome plugin that lets you edit &lt;code&gt;shape-outside&lt;/code&gt; properties in CSS&lt;/li&gt;
&lt;li&gt;speech recognition to have voice commands&lt;/li&gt;
&lt;li&gt;leap motion to switch between pages&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All demos are available at &lt;a href=&#34;http://adobe.github.io&#34;&gt;http://adobe.github.io&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Other features coming up:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-webkit-mask&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-webkit-clip-path&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;blend modes in canvas&lt;/li&gt;
&lt;li&gt;blend modes in CSS&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;trick: use canvas as a mask for page transtions&lt;/p&gt;
&lt;p&gt;WE DO OPENSOURCE (weeeeee): &lt;a href=&#34;http://html.adobe.com/opensource&#34;&gt;http://html.adobe.com/opensource&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;rethinking-css-best-practicesbr&#34;&gt;Rethinking CSS Best Practices&lt;br&gt;★★★★★&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Renato Iwashima, Yahoo&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Talk is introducing Atomic CSS.&lt;/p&gt;
&lt;p&gt;Grouping properties by selectors doesn&amp;rsquo;t scale. When you have lots of places
using the same style you end up with something like:&lt;/p&gt;
&lt;pre class=&#34;brush:css&#34;&gt;
.class1,
.class2,
.class3 { /*some style */ }
&lt;/pre&gt;
&lt;p&gt;Other ideas: have a reusable class. But once again, when you want to reuse that
class and override, you have specificity problems.&lt;/p&gt;
&lt;p&gt;Standard architecture for a site&amp;rsquo;s CSS (page1);&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;normalize&lt;/li&gt;
&lt;li&gt;Layout&lt;/li&gt;
&lt;li&gt;Reusable patterns&lt;/li&gt;
&lt;li&gt;Module css 1&lt;/li&gt;
&lt;li&gt;Module css 2&lt;/li&gt;
&lt;li&gt;module css 3&lt;/li&gt;
&lt;li&gt;etc&lt;/li&gt;
&lt;li&gt;page specific styles for page 1&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Standard architecture for a site&amp;rsquo;s CSS (page2);&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;normalize&lt;/li&gt;
&lt;li&gt;Layout&lt;/li&gt;
&lt;li&gt;Reusable patterns&lt;/li&gt;
&lt;li&gt;Module css 1&lt;/li&gt;
&lt;li&gt;Module css 3&lt;/li&gt;
&lt;li&gt;module css 5&lt;/li&gt;
&lt;li&gt;etc&lt;/li&gt;
&lt;li&gt;page specific styles for page 2&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Problems:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Poor caching&lt;/li&gt;
&lt;li&gt;limited reusability of styles&lt;/li&gt;
&lt;li&gt;specificity wars&lt;/li&gt;
&lt;li&gt;maintainability&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;What we want instead (as an architecture for a page:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;normalize&lt;/li&gt;
&lt;li&gt;reusable library of atomic classes&lt;/li&gt;
&lt;li&gt;pages pecific styles&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;About semantic class names: other than microformats, class names are used for
presentational purpose or JS hooks.&lt;/p&gt;
&lt;p&gt;Semantic example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;.title&lt;/code&gt;&amp;hellip;means bold? large? text?&lt;/li&gt;
&lt;li&gt;&lt;code&gt;.bold&lt;/code&gt;, &lt;code&gt;.large&lt;/code&gt; =&amp;gt; THOSE are semantic classes for a presentational
perspective. When you read them you can tell how they look. They carry much
MORE meaning that &lt;code&gt;.title&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But we stop because best practices recommend to style based on content. BUT WHY?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;seo and responsive web design&lt;/li&gt;
&lt;li&gt;html5 spec (the spec actually says that authors are encouraged to use the
class attribute to describe content)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;BUT a number of people are suggesting that this might not be a good idea for
large scale websites. &lt;a href=&#34;http://nicolasgallagher.com/about-html-semantics-front-end-architecture/&#34;&gt;Nicolas Gallagher&lt;/a&gt;:
&amp;ldquo;the most reusable classnames are the ones independent of the content&amp;rdquo;. Nicole
Sullivan has the same idea: &amp;ldquo;keep specificity low, abstract repeating visual
patterns&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;&amp;hellip;Here comes Atomic CSS. Naming is inspired by Zen Coding (Emmet):&lt;/p&gt;
&lt;pre class=&#34;brush:css&#34;&gt;
    .Fl-start { float: left; }
    .Fl-end { float: right; }
    .Fl-n { float: none; }
    .Mstart-10 { margin-left: 10px }
&lt;/pre&gt;
&lt;p&gt;MANAGE TEMPLATES INSTEAD OF STYLESHEETS&lt;br&gt;
There are lots of template engines and they&amp;rsquo;re smarter than CSS&lt;/p&gt;
&lt;p&gt;What should be in a CSS file? fundamental classes, helpers. That&amp;rsquo;s it!&lt;/p&gt;
&lt;p&gt;Adantages:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;reduces styles scope&lt;/li&gt;
&lt;li&gt;reduces stylesheet bloat&lt;/li&gt;
&lt;li&gt;improves perf&lt;/li&gt;
&lt;li&gt;removes dependencies&lt;/li&gt;
&lt;li&gt;allows to share content&lt;/li&gt;
&lt;li&gt;leverages cache by being immutable&lt;/li&gt;
&lt;li&gt;facilitates RTL/LTR interface switch&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Use case: Media object&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    &lt;div class=&#34;media&#34;&gt;
      &lt;a rel=&#34;noopener noreferrer&#34; class=&#34;pull-left&#34;&gt;&lt;/a&gt;
      &lt;div class=&#34;media-body&#34;&gt;&lt;/div&gt;
    &lt;/div&gt;
&lt;/pre&gt;
&lt;p&gt;But what about column layout? Is &amp;ldquo;media object&amp;rdquo; still a relevant name for that?&lt;/p&gt;
&lt;p&gt;The Atomic CSS version:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    &lt;div class=&#34;Bfc&#34;&gt; (Bfc: block formatting context)
      &lt;div class=&#34;Fl-start&#34;&gt;&lt;/div&gt;
      &lt;div class=&#34;Fl-end&#34;&gt;&lt;/div&gt;
    &lt;/div&gt;
&lt;/pre&gt;
&lt;p&gt;Use case: hero unit&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    &lt;h1 class&#34;Fz-xl Fw-b&#34;&gt;Heading&lt;/h1&gt;
    &lt;p class=&#34;Fz-l Fw-200&#34;&gt;Tagline&lt;/p&gt;
&lt;/pre&gt;
&lt;p&gt;Is that hard? No because it has real meaning.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;CSS bloat vs. HTML bloat, aren&amp;rsquo;t you just shifting complexity?&lt;/em&gt;&lt;br&gt;
Well, data needs to live somewhere&lt;br&gt;
Besides, look at &lt;code&gt;.wrapper&lt;/code&gt; vs &lt;code&gt;.bfc&lt;/code&gt; (semantic names are longer than ACSS ones) and those
compress better (good GZIP compression because of repetition)&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Aren&amp;rsquo;t you just inventing inline styles again?&lt;/em&gt;&lt;br&gt;
inline styles have a HUGE specificity and are verbose. Not ACSS. They have
abstractions, they take care of cross-browser problems.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Performance?&lt;/em&gt;&lt;br&gt;
Numbers are really nice. They got down to a 18kb super reusable package
containing all the presentational classnames. &lt;a href=&#34;http://my.yahoo.com&#34;&gt;http://my.yahoo.com&lt;/a&gt; has only 3kb
of page specific CSS.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;http://bit.ly/atomiccss&#34;&gt;http://bit.ly/atomiccss&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;always-bet-on-js-convergence-of-operating-system-and-browserbr&#34;&gt;Always bet on JS, convergence of operating system and browser&lt;br&gt;★★★★★&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Nick Desaulniers, Mozilla&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Nick is an &amp;ldquo;OpenSource zealot&amp;rdquo;. He led protests in SF. OPEN SOURCE PROTESTS.
Talk is about convergence of OS and browser and how HTML5/JS/CSS should win.&lt;/p&gt;
&lt;p&gt;Users shouldn&amp;rsquo;t care about &amp;ldquo;native vs web&amp;rdquo; because the limit is not clear
anymore: webOS, firefoxOS, Tizen, and many others are blurring the line.&lt;/p&gt;
&lt;p&gt;Web&amp;rsquo;s number one advantage is &lt;strong&gt;portability&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;&amp;ldquo;but native apps have better access to hardware!&amp;quot;&lt;/em&gt;&lt;br&gt;
=&amp;gt; this should be fixed. Let&amp;rsquo;s file bugs against browsers. Mozilla has been
adding a lot of APIs to access native hardware. You shouldn&amp;rsquo;t have to rely on
apache cordova to do that.&lt;/p&gt;
&lt;p&gt;open webapps (demo installing that on windows, osx, android. wow.)
&lt;a href=&#34;http://nickdesaulniers.github.io/blog/2013/04/03/basic-jit/&#34;&gt;more on JITs&lt;/a&gt;
(Nick&amp;rsquo;s blog)&lt;/p&gt;
&lt;p&gt;A plan for html5 to become the king of the jungle:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;more device apis&lt;/li&gt;
&lt;li&gt;consistent perf improvements&lt;/li&gt;
&lt;li&gt;rocking developer tools&lt;/li&gt;
&lt;li&gt;partnering with carrieres and handset manufactureres&lt;/li&gt;
&lt;li&gt;target growing markets&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;slid.es/nickdesaulniers/jsos&lt;/p&gt;
&lt;h2 id=&#34;react-rethinking-best-practicesbr&#34;&gt;React: Rethinking best practices&lt;br&gt;★★★★★&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Pete Hunt, Facebook&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Pretty cool talk on how reactJS is built. It explained the philosophy behind it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;use JS to express components&lt;/li&gt;
&lt;li&gt;reuse components when building components&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;ReactJS is at the core of what FB uses. Seems pretty slick.&lt;/p&gt;
&lt;p&gt;The main interesting thing to me is their use of a &lt;strong&gt;virtual DOM&lt;/strong&gt;. That lets
them virtually update and read from the DOM without actually ever touching it.
That means you can batch updates to the DOM but also batch reads and do all
sorts of crazy optimizations. For instance they diff the virtual DOM against
the real one. Reusing elements becomes super easy.&lt;/p&gt;
&lt;p&gt;Interesting part: everything done with virtual DOM does not need to touch the
DOM, which means it can be moved to a separate process by using webworkers.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;http://reactjs.org&#34;&gt;http://reactjs.org&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;browser-dance-partybr&#34;&gt;Browser Dance Party&lt;br&gt;★★★★☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Jordan Santell, Mozilla&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Analyzer node to get data about frequency and time domain.&lt;/p&gt;
&lt;pre class=&#34;brush:js&#34;&gt;
    var a = ctx.createAnalyser();
    a.fftSize = 512;
    var freq = new Uint8Array(256);
    setInterval(function() {
      a.getBytFrequencyData(freq);
    }, 20);
&lt;/pre&gt;
&lt;p&gt;Downside: &lt;code&gt;setInterval&lt;/code&gt; has no knowledge of audio. Instead:&lt;/p&gt;
&lt;pre class=&#34;brush:js&#34;&gt;
    var BUFFER_SIZE = 2048;
    var p = ctx.createScriptProcessor(BUFFER_SIZE);
    a.fftSize = 1024;
    var fft = new Uint8Array(256);
    p.onaudioprocess = function() { a.getByteFrequency...}
&lt;/pre&gt;
&lt;p&gt;Beat detection&lt;br&gt;
beat = drastic changes in sound energy&lt;/p&gt;
&lt;p&gt;1st algorithm:&lt;br&gt;
average magnitude. When it goes over a certain threshold, that&amp;rsquo;s a beat. Very simple.
Depending on the type of music you&amp;rsquo;re trying&lt;/p&gt;
&lt;h2 id=&#34;image-layout-algorithmsbr&#34;&gt;Image Layout Algorithms&lt;br&gt;★★★★☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Christopher Chedeau, Facebook&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;No doc on images layout algorithms, did some research on the topic.&lt;/p&gt;
&lt;h3 id=&#34;fixed-grid-layouts&#34;&gt;Fixed Grid Layouts&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;square grid =&amp;gt; from windows 3.1 to ios7. This is super duper easy.&lt;/li&gt;
&lt;li&gt;contain grid =&amp;gt; shrink to fit inside, which results in whitespace if you have
mixed aspect ratios. Whitespace is bad in general. You want to use as much
space to show photos&lt;/li&gt;
&lt;li&gt;cover grid =&amp;gt; shrink to cover, which means you crop some pictures.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;background-size: contain/cover&lt;/code&gt; already exists in CSS and can do that for you!&lt;/p&gt;
&lt;h3 id=&#34;less-boring-grids&#34;&gt;Less Boring Grids&lt;/h3&gt;
&lt;p&gt;500px demo. Where images sometimes take 1 grid items, sometimes 2, etc. Leads
to more iteresting photo page.&lt;/p&gt;
&lt;p&gt;Technique: get a canvas (4x2) and some shapes. You then fill canvas with shapes.&lt;/p&gt;
&lt;p&gt;Demo with click to enlarge/minimize&lt;/p&gt;
&lt;p&gt;How it works: maintain 2 pointers with the first position available for a 2x2 square and 1x1 square.
Not clear what the win is?&lt;/p&gt;
&lt;h3 id=&#34;cropping-algorithm&#34;&gt;Cropping Algorithm?&lt;/h3&gt;
&lt;p&gt;Problem with cropping is that you have to find the best crop. Cropping
algorithms are a waste of time. Crop less. Crop square. That&amp;rsquo;s the less risky
thing to do.&lt;/p&gt;
&lt;h3 id=&#34;adaptive-grids&#34;&gt;Adaptive Grids&lt;/h3&gt;
&lt;h4 id=&#34;organize-by-colums&#34;&gt;organize by colums&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Means landscape will be smaller than portrait&lt;/strong&gt;. Example: 9gag.&lt;/p&gt;
&lt;p&gt;Algorithm for this: fill smallest column
expand to two column if two columns are the same height. In reality, 2 columns being exactly the same height is really low. Instead, use a coarse grid (if columns are more or less the same height, up to 10px different). Coarse grid means that you have to crop up to 10px&lt;/p&gt;
&lt;h4 id=&#34;organize-by-rows&#34;&gt;organize by rows&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Means portrait images will be smaller than landscape&lt;/strong&gt;. Example: Flickr.&lt;/p&gt;
&lt;p&gt;Laying out by rows can be considered the same as laying out for text. Turns out
LaTeX has a super cool algorithm for that.&lt;/p&gt;
&lt;h3 id=&#34;irregular-layouts&#34;&gt;Irregular Layouts&lt;/h3&gt;
&lt;p&gt;Aspect ratio of √2. If you devide a √2 ratio image in 2, you get 2 √2 ratio pics. You can exploit that to get cool effects.&lt;/p&gt;
&lt;h3 id=&#34;holy-grail&#34;&gt;Holy Grail&lt;/h3&gt;
&lt;p&gt;Kristy Mannix Photography (manual layout)
Google search results (not clear what they do but it&amp;rsquo;s good)&lt;/p&gt;
&lt;h3 id=&#34;images-layout-analysis&#34;&gt;Images layout Analysis&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Grid, colums, row, irregular&lt;/li&gt;
&lt;li&gt;crop?&lt;/li&gt;
&lt;li&gt;resize, whitespace&lt;/li&gt;
&lt;li&gt;human intervention?&lt;/li&gt;
&lt;li&gt;sizes?&lt;/li&gt;
&lt;li&gt;order is conserved?&lt;/li&gt;
&lt;li&gt;does it maximizes bigger?&lt;/li&gt;
&lt;li&gt;can you insert/remove/move images?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href=&#34;http://blog.vjeux.com/category/image&#34;&gt;http://blog.vjeux.com/category/image&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;pdf-jsbr&#34;&gt;PDF JS&lt;br&gt;★★★★☆&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Brendan Dahl, Mozilla&lt;/strong&gt;&lt;/p&gt;
&lt;h3 id=&#34;pdf-format-history&#34;&gt;PDF format history&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;camelot (1991) =&amp;gt; pdf (1993)&lt;/li&gt;
&lt;li&gt;PDF got lots of features over the years (3d modeling!!, video, audio, flash, javascript!)&lt;/li&gt;
&lt;li&gt;PDF became a standard in 2008&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;whats-in-a-pdf&#34;&gt;What&amp;rsquo;s in a PDF?&lt;/h3&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    %PDF-1.7 &lt;&lt; Header
    2 0 obj
    &lt;&lt;
       /Type /Pages
    &gt;&gt;
    xref tables
    ...trailer
&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;dictionaries in PDF &lt;code&gt;&amp;lt;&amp;lt; /Length 44 &amp;gt;&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;strings in PDF &lt;code&gt;(Hello World!)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;etc&amp;hellip;syntax is all weird. Seriously!&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;why-pdfjs&#34;&gt;Why pdf.js?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;security (Adobe has had lots of problems with that in the past)&lt;/li&gt;
&lt;li&gt;user experience (no Adobe updates prompts)&lt;/li&gt;
&lt;li&gt;performance (for small PDFs, not firing up a third party tool is better)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;rendering-a-pdf&#34;&gt;Rendering a PDF&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;grab the bytes (via xhr2)&lt;/li&gt;
&lt;li&gt;parsing, extracting&lt;/li&gt;
&lt;li&gt;render on canvas&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Problems:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;PDF supports an awful lot of  image types&lt;/li&gt;
&lt;li&gt;PDF supports an awful lot of  fonts&lt;/li&gt;
&lt;li&gt;PDF has colorspaces (cmyk space for instance)&lt;/li&gt;
&lt;li&gt;PDF has PostScript functions&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;about-pdfjs&#34;&gt;About pdf.js&lt;/h3&gt;
&lt;p&gt;Text is really hard (glyphs,copy paste, unicode, left-to-right vs right-to-left)&lt;/p&gt;
&lt;p&gt;Text selection is achieved through a transparent overlay on top of canvas&lt;/p&gt;
&lt;p&gt;Solution do janky scrolling: webworkers and &lt;code&gt;setTimeout&lt;/code&gt; to let the browser do
its thing, priorize rendering, etc.&lt;/p&gt;
&lt;p&gt;Timeline:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;april 2012 =&amp;gt; pdfjs landed in nightly&lt;/li&gt;
&lt;li&gt;january 2013 =&amp;gt; ion monkey (new js engine)&lt;/li&gt;
&lt;li&gt;february 2013 =&amp;gt; pdfjs makes it to firefix stable&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Improvements since first launch:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;range request loading (don&amp;rsquo;t download all the things at once)&lt;/li&gt;
&lt;li&gt;incremental rendering (sending chunks of 100 operations at once)&lt;/li&gt;
&lt;li&gt;supports the majority of common PDF features&lt;/li&gt;
&lt;li&gt;renders many PDFs quickly&lt;/li&gt;
&lt;li&gt;works in FFx, Chrome, IE9+, Opera&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Still no support for forms and JS, working on that.&lt;/p&gt;
&lt;h3 id=&#34;lessons-learned&#34;&gt;Lessons learned:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;plan for asynchronous operations&lt;/li&gt;
&lt;li&gt;do as much as possible in workers&lt;/li&gt;
&lt;li&gt;unit tests. write some. early. they&amp;rsquo;re always a good idea.&lt;/li&gt;
&lt;li&gt;program defensively&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href=&#34;http://github.com/mozilla/pdf.js&#34;&gt;http://github.com/mozilla/pdf.js&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;talks-i-could-not-attend&#34;&gt;Talks I Could Not Attend&lt;/h2&gt;
&lt;p&gt;The format of the conference (13 parallel tracks!) made some sessions very
busy, to a point where not everyone could fit in the room (nope, not even
space to sit in the alley or stand in the back). I&amp;rsquo;ll have to watch later:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;New rules for JavaScript&lt;/em&gt;, Kyle Simpson&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Which way is forward&lt;/em&gt;, Doug Crockford&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    <item>
      <title>Secrets Of The JavaScript Ninja</title>
      <link>https://arnaudbrousseau.com/notes/secrets-of-the-javascript-ninja.html</link>
      <pubDate>Fri, 18 Oct 2013 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/secrets-of-the-javascript-ninja.html</guid>
      <description>&lt;h2 id=&#34;what-is-this-book-who-is-it-for&#34;&gt;What Is This Book? Who Is It For?&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;http://www.manning.com/resig/&#34;&gt;Secrets Of The JavaScript Ninja&lt;/a&gt; is designed
for intermediate to advanced JavaScript programmers. It expects you to have a
firm understanding of JavaScript and a working knowledge of HTML/CSS.&lt;br&gt;
The strength of this book lies in its ability to force you to
revisit concepts most JS programmers (including myself) always take for
granted. It puts the focus on functions as objects, function invoking, closures,
cross-browsers strategies, etc.&lt;/p&gt;
&lt;p&gt;Resig sets the tone pretty early on. After a short introduction in a chapter
titled &amp;ldquo;Arming With Testing And Debugging&amp;rdquo; he tells us about the importance of
testing and goes on to explain how one can create a simple JavaScript
&lt;code&gt;assert&lt;/code&gt; method and its associated test runner. Testing is usually briefly
mentioned towards the end of a textbook. Not this time. Testing is mentioned
throughout the book.&lt;/p&gt;
&lt;p&gt;So why am I writing about reading &amp;ldquo;Secrets of the JavaScript Ninja&amp;rdquo;?
Several reasons:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Writing about something helps you remember it better&lt;/li&gt;
&lt;li&gt;I&amp;rsquo;m adding some reference and extra information here and there.&lt;/li&gt;
&lt;li&gt;Hopefully this is useful to you, the reader, to a) get a sense of what&amp;rsquo;s in
this book and b) get better at JavaScript!&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The remainder of this article is organized in sections, matching roughly the
order of the book&amp;rsquo;s chapters. In each of those sections I go through what
picked my interest while reading the book, with a focus on concepts that
&amp;ldquo;clicked&amp;rdquo; and interesting discoveries.&lt;/p&gt;
&lt;h2 id=&#34;functions&#34;&gt;Functions&lt;/h2&gt;
&lt;p&gt;Created via the &lt;code&gt;Function&lt;/code&gt; constructor, functions are special objects with
one superpower: they can be &lt;strong&gt;invoked&lt;/strong&gt;. Besides that, functions are object and
nothing but objects:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;they&amp;rsquo;re created via literals &lt;code&gt;function &amp;lt;optionalName&amp;gt; (&amp;lt;optionalArguments) {&amp;lt;functionBody&amp;gt;}&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;they can be assigned to variables or properties&lt;/li&gt;
&lt;li&gt;they can be passed as function parameters and returned as function results&lt;/li&gt;
&lt;li&gt;they can have properties and methods. For instance each function has a &lt;code&gt;name&lt;/code&gt;
property and a &lt;code&gt;call&lt;/code&gt; and &lt;code&gt;apply&lt;/code&gt; method. More on that later.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;function-declaration&#34;&gt;Function Declaration&lt;/h3&gt;
&lt;p&gt;Two main ways to declare a function:&lt;/p&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
    // option 1
    function blah() { console.log(&#39;called&#39;); }
    // option 2
    var blah = function() { console.log(&#39;called&#39;); };
&lt;/pre&gt;
&lt;p&gt;In both cases the function can be called via &lt;code&gt;blah()&lt;/code&gt; after its declaration.
However there&amp;rsquo;s a crucial difference: in the first case the function is
&lt;strong&gt;named&lt;/strong&gt; &lt;code&gt;blah&lt;/code&gt; which means the function will be assigned a property &lt;code&gt;name&lt;/code&gt;
with the value &lt;code&gt;blah&lt;/code&gt;.&lt;br&gt;
In the second case, we&amp;rsquo;re assigning an &lt;strong&gt;anonymous&lt;/strong&gt; function to the variable
&lt;code&gt;blah&lt;/code&gt;. The function&amp;rsquo;s &lt;code&gt;name&lt;/code&gt; property in this case will be &lt;code&gt;&#39;&#39;&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;arguments-and-invocation&#34;&gt;Arguments and Invocation&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;this&lt;/code&gt; and &lt;code&gt;arguments&lt;/code&gt; are implicit parameters passed to every function. They
are just that. Parameters. The difference between &lt;code&gt;this&lt;/code&gt;, &lt;code&gt;arguments&lt;/code&gt; and
standard function parameters is that they are &lt;em&gt;implicit&lt;/em&gt;. You won&amp;rsquo;t see them in
function signatures but they&amp;rsquo;ll be available from within function bodies.&lt;/p&gt;
&lt;h4 id=&#34;arguments&#34;&gt;Arguments&lt;/h4&gt;
&lt;p&gt;&lt;code&gt;arguments&lt;/code&gt; represent a list of all arguments passed to a function. It has
array-like accessors (&lt;code&gt;arguments[i]&lt;/code&gt;) and properties (&lt;code&gt;arguments.length&lt;/code&gt;) but
&lt;strong&gt;is not an array&lt;/strong&gt; (&lt;code&gt;arguments.slice(1)&lt;/code&gt; fails for instance).&lt;br&gt;
How can you get around that?&lt;/p&gt;
&lt;pre class=&#34;brush: js;&#34;&gt;
    Object.prototype.toString.call
    Array.prototype.slice.call
    //...etc
&lt;/pre&gt;
&lt;h4 id=&#34;invoking-a-function-and-this&#34;&gt;Invoking a Function, and &lt;code&gt;this&lt;/code&gt;&lt;/h4&gt;
&lt;p&gt;&lt;code&gt;this&lt;/code&gt; is defined as the &lt;strong&gt;function context&lt;/strong&gt;. Available within a function body,
&lt;code&gt;this&lt;/code&gt; should really be referred to as  &lt;strong&gt;invocation context&lt;/strong&gt;, because its value
varies based on the way a function is invoked:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;as a function, &lt;code&gt;this&lt;/code&gt; refers to the global context &lt;code&gt;window&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;as a method, &lt;code&gt;this&lt;/code&gt; refers to the object owning it&lt;/li&gt;
&lt;li&gt;as a constructor, &lt;code&gt;this&lt;/code&gt; refers to the newly created object&lt;/li&gt;
&lt;li&gt;via &lt;code&gt;call&lt;/code&gt; or &lt;code&gt;apply&lt;/code&gt;, &lt;code&gt;this&lt;/code&gt; is passed in and can be what we want&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;referencing-functions&#34;&gt;Referencing Functions&lt;/h3&gt;
&lt;p&gt;Referencing functions from within themselves is necessary to achieve recursion.
Resig enumerates four ways.&lt;/p&gt;
&lt;p&gt;First option: through a named function. Nothing out of the ordinary.&lt;/p&gt;
&lt;pre class=&#34;brush: js; highlight: [1,3]&#34;&gt;
    function fact(x) {
        if (x !== 1) {
            return x * fact(x - 1);
        } else {
            return 1;
        }
    };
&lt;/pre&gt;
&lt;p&gt;Second option: through a method name. Note the danger: if we decide to change
that method&amp;rsquo;s name to &lt;code&gt;newfact&lt;/code&gt;, we&amp;rsquo;ll have to remember to change the inner
reference to &lt;code&gt;this.newfact&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&#34;brush: js; highlight: [2,4]&#34;&gt;
    var math = {
        &#39;fact&#39;: function (x) {
            if (x !== 1) {
                return x * this.fact(x - 1);
            } else {
                return 1;
            }
        }
    };
&lt;/pre&gt;
&lt;p&gt;Third option: through inline name. This addresses the shortcoming of the
previous solution.&lt;/p&gt;
&lt;pre class=&#34;brush: js; highlight: [2,4]&#34;&gt;
    var math = {
        &#39;fact&#39;: function myfact(x) {
            if (x !== 1) {
                return x * myfact(x - 1);
            } else {
                return 1;
            }
        }
    };
&lt;/pre&gt;
&lt;p&gt;Last option: &lt;code&gt;callee&lt;/code&gt; (going to go away in later versions of JS, use sparingly).&lt;/p&gt;
&lt;pre class=&#34;brush: js; highlight: [2,4]&#34;&gt;
    var math = {
        &#39;fact&#39;: function (x) {
            if (x !== 1) {
                return x * arguments.callee(x - 1);
            } else {
                return 1;
            }
        }
    };
&lt;/pre&gt;
&lt;h3 id=&#34;auto-memoizing-functions&#34;&gt;Auto-Memoizing Functions&lt;/h3&gt;
&lt;p&gt;Memoizing by using the object nature of functions:&lt;/p&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
    function getElements(name) {
        if (!getElements.cache) { getElements.cache = {}; }
        return getElements.cache[name] =
            getElements.cache[name] ||
            document.getElementsByTagName(name);
    };
&lt;/pre&gt;
&lt;p&gt;You can easily guess how useful these techniques are in a library like
jQuery (actually probably more in Sizzle, jQuery&amp;rsquo;s DOM access library).&lt;/p&gt;
&lt;h3 id=&#34;function-overloading&#34;&gt;Function Overloading&lt;/h3&gt;
&lt;p&gt;Functions have a &lt;code&gt;length&lt;/code&gt; property, which corresponds to the number of
arguments declared in their signature. By comparing &lt;code&gt;fn.length&lt;/code&gt; and
&lt;code&gt;arguments.length&lt;/code&gt;, function overloading can be implemented in a cool way:&lt;/p&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
    function addMethod(object, name, fn) {
        var old = object[name];
        object[name] = function() {
            if (fn.length == arguments.length) {
                return fn.apply(this, arguments);
            } else if (typeof old === &#39;function&#39;) {
            return old.apply(this, arguments);
            }
        };
    };

    // Overloading then becomes a piece of cake. Pretty neat right?
    var obj = {};
    addMethod(obj, &#39;method&#39;, function() { /* do something */ });
    addMethod(obj, &#39;method&#39;, function(a) { /* do something with a */ });
    addMethod(obj, &#39;method&#39;, function(a, b) { /* do something with a and b */ });
&lt;/pre&gt;
&lt;h2 id=&#34;closures&#34;&gt;Closures&lt;/h2&gt;
&lt;p&gt;Closures are probably one of the most confusing concepts when someone with a
classical object-oriented background comes to JavaScript.&lt;/p&gt;
&lt;p&gt;Resig&amp;rsquo;s definition of it: &lt;em&gt;&amp;ldquo;closures allow a function to access all the
variables, as well as other functions, that are in scope when the function
itself is declared.&amp;quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Later in the chapter: &lt;em&gt;&amp;ldquo;That&amp;rsquo;s what closures are all about. They create a
&amp;lsquo;safety bubble,&amp;rsquo; if you will, of the function and the variables that are in
scope at the point of the function&amp;rsquo;s declaration [&amp;hellip;] This &amp;lsquo;bubble,&amp;rsquo;
containing the function and its variables, stays around as long as the function
itself does.&amp;quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s look at some code samples to go over the main use cases for closures.&lt;/p&gt;
&lt;h3 id=&#34;private-variables&#34;&gt;Private Variables&lt;/h3&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
    function Counter() {
        var count = 0; // visibility limited to Counter&#39;s inner scope
        this.increment = function() { count++; }
        this.getCount = function() { return count; }
    };
    // Can&#39;t view/modify count from here. You have to go through Counter.getCount()
&lt;/pre&gt;
&lt;h3 id=&#34;callbacks-and-timers&#34;&gt;Callbacks And Timers&lt;/h3&gt;
&lt;p&gt;Callback and timers are in the same vain because the idea here is to use a
closure to host values that the function scheduled to be called back is going
to need when executing. Understanding that a closure&amp;rsquo;s environment (function,
variables) stays around even when the outer scope has finished its execution is
fundamental.&lt;/p&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
    /**
     * Callback
     */
    var elem = document.getElementById(&#39;my-elem&#39;);
    $.ajax({
        url: &#39;/my-endpoint&#39;,
        success: function() {
            // Here we have access to elem because our outer anonymous
            // function had access to it when it was declared.
            elem.innerHTML(&#39;callback executed successfully&#39;);
        }
    });

    /**
     * Timer
     */
     function count() {
        var count = 0;
        setInterval(function() {
            // Here we have access to count for the same reason: our outer
            // anonymous function has access to it when it is declared.
            console.log(&#39;Count is &#39; + count);
            count++;
        }, 1000);
     };
&lt;/pre&gt;
&lt;h3 id=&#34;binding-function-contexts&#34;&gt;Binding Function Contexts&lt;/h3&gt;
&lt;p&gt;Here closures are used to set the context of functions properly.&lt;/p&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
    // Simple example
    function bind(context, name) {
        return function() {
            // Access to context and name via closure
            return context[name].apply(context, arguments);
        };
    };

    // Example from PrototypeJS
    Function.prototype.bind = function() {
        var fn = this;
        // Turn arguments into a real array
        var args = Array.prototype.slice.call(arguments);
        var ctx = args.shift(); // args is now args[1:n] and object refers
                                // to the first argument
        return function() {
            return fn.apply(
                ctx,
                // `args` refers to the arguments specified at &#34;bind-time&#34;
                // and `arguments` refers to the arguments specified at
                // &#34;call-time&#34;.
                // This lets us specify &#34;default&#34; arguments and bind function
                // context at the same time.
                args.concat(Array.prototype.slice.call(arguments))
            );
        };
    };

    // Sample usage
    var nameSpace = { a: 1, plop: function(b, c) { return this.a + b + c; } }
    var basicBound = basicBind(nameSpace, &#34;plop&#34;);
    var bound = nameSpace.plop.bind(nameSpace, 2);
    basicBound(3, 5) // returns 9 (1 + 3 + 5)
    bound(3); // returns 6 (1 + 2 + 3)
&lt;/pre&gt;
&lt;h3 id=&#34;partial-function-application-currying&#34;&gt;Partial Function Application, Currying&lt;/h3&gt;
&lt;p&gt;Currying and partials are super simple if you understand &lt;code&gt;bind&lt;/code&gt;&amp;rsquo;s definition
above. It&amp;rsquo;s essentially the same trick.&lt;/p&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
    Function.prototype.curry = function() {
        var fn = this;
        var args = Array.prototype.slice.call(arguments); // &#34;curry-time&#34; args

        return function() {
            return fn.apply(
                // unmodified context
                this,
                // concatenation of &#34;curry-time&#34; and &#34;call-time&#34; args, in this order
                args.concat(Array.prototype.slice.call(arguments))
            );
        };
    };

    Function.prototype.partial = function() {
        var fn = this;
        var args = Array.prototype.slice.call(arguments);

        return function() {
            // Here the args manipulation is a bit more tricky since you can
            // leave an undefined param for partial application later on.
            // (see sample usage)
            var arg = 0;
            for (var i=0; i &lt; args.length &amp;&amp; arg &lt; arguments.length; i++) {
                if (args[i] === undefined) {
                    args[i] = arguments[arg];
                    arg++;
                }
            }
            return fn.apply(this, args);
        };
    };

    // Sample usage
    var myFunction = function(a, b, c) { return a + b + c; };
    var curried = myFunction.curry(1, 2);
    var partial = myFunction.partial(undefined, 2);
    curried(3); // 6
    partial(1, 4); // 7
&lt;/pre&gt;
&lt;h3 id=&#34;function-wrapping&#34;&gt;Function Wrapping&lt;/h3&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
    function wrap(object, method, wrapper) {
        // Keeps a reference to the original method
        var fn = object[method];

        return object[method] = function() {
            // The wrapper is called with
            // - the original function to be wrapped, as a first argument
            // - the list of arguments to call the original function with
            return wrapper.apply(this, [fn.bind(this)].concat(
                Array.prototype.slice.call(arguments)));
        };
    };

    // Sample usage: automatically adds try/catch on event listeners
    wrap(HTMLElement.prototype, &#34;addEventListener&#34;, function(old, type, handler, prop) {
        old(type, function() {
            try {
                handler.apply(this, arguments);
            } catch(e) {
                // Handle error
            }
        }, prop);
    };
&lt;/pre&gt;
&lt;h3 id=&#34;immediate-functions&#34;&gt;Immediate Functions&lt;/h3&gt;
&lt;p&gt;Closures are also crucial in IIFEs (&lt;em&gt;Immediately Invoked Function Expression&lt;/em&gt;).
Have you always wonder why &lt;code&gt;(function() {})()&lt;/code&gt; works the way it does? Well:&lt;/p&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
    // an IIFE like...
    (function() {/* body */})()
    // ...is EXACTLY the same as...
    var myFunc = function() {/* body */};
    (myFunc)();
&lt;/pre&gt;
&lt;p&gt;This is clever because it means the body of our IIFE is going to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;execute immediately after its declaration&lt;/li&gt;
&lt;li&gt;have a reference to the outside scope through the closure it creates&lt;/li&gt;
&lt;li&gt;keep all its variables and inner functions isolated and hidden from outside&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Hence IIFEs are a nice way to create isolated scopes for independent pieces of
functionality. It guarantees no conflict with and no leakage to the outside
world. That&amp;rsquo;s why most libraries, including jQuery, are wrapped in a IIFE.&lt;/p&gt;
&lt;p&gt;Note that you can pass params to an IIFE:&lt;br&gt;
&lt;code&gt;(function(a, b) {return a + b;})(1, 2)&lt;/code&gt;&lt;/p&gt;
&lt;h2 id=&#34;prototypes&#34;&gt;Prototypes&lt;/h2&gt;
&lt;p&gt;JavaScript Prototypes represent a hard-to-grasp concept because most of us
think about it with the classical object oriented background in the back of our
minds.&lt;/p&gt;
&lt;p&gt;In a few sentences Resig made me realize how wrong I&amp;rsquo;ve been thinking
about prototypes: &lt;em&gt;&amp;ldquo;prototypes are a convenient way to define types of objets,
but they&amp;rsquo;re actually a feature of functions&amp;rdquo;&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;And later: &amp;ldquo;&lt;em&gt;each object in JavaScript has an implicit property named
&lt;code&gt;constructor&lt;/code&gt; that references the constructor [function] that was used to
create the object. And because the prototype is a property of the constructor
[function], each object has a way to find its prototype.&lt;/em&gt;&amp;rdquo;&lt;br&gt;
Note that I appended &lt;em&gt;[function]&lt;/em&gt; to make you realize that constructors are not
a special feature of the language. In fact, &lt;strong&gt;a &amp;ldquo;constructor&amp;rdquo; is just a
function invoked in a given way&lt;/strong&gt; (using &lt;code&gt;new&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Remember what we discussed before:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;functions are just objects with the privilege of being &lt;strong&gt;invoked&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;invoking a function with &lt;code&gt;new&lt;/code&gt; will call it with a context set to an empty
object. That object will be returned when the function is done executing.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;References in objects are resolved on the object itself first. However when a
property fails to be found on the object itself, a property lookup is made &lt;strong&gt;on
the object contructor&amp;rsquo;s &lt;code&gt;prototype&lt;/code&gt; property&lt;/strong&gt;. And you guessed already: if an
object constructor&amp;rsquo;s &lt;code&gt;prototype&lt;/code&gt; references an object, lookup can be performed
on that object constructor&amp;rsquo;s &lt;code&gt;prototype&lt;/code&gt;. And so on and so forth. That&amp;rsquo;s what
&lt;strong&gt;prototype chain lookup&lt;/strong&gt; means.&lt;/p&gt;
&lt;p&gt;Take the following snippet:&lt;/p&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
    function A() { this.foo = &#39;bar&#39;; }
    var a = new A();
    A.prototype.baz = &#39;blah&#39;;

    console.log(a.baz); // logs &#39;blah&#39;
&lt;/pre&gt;
&lt;p&gt;What happens in this snippet? A lot!&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a function &lt;code&gt;A&lt;/code&gt; is defined on line 1&lt;/li&gt;
&lt;li&gt;&lt;code&gt;A&lt;/code&gt; is invoked with &lt;code&gt;new&lt;/code&gt; on line 2. That means &lt;code&gt;A&lt;/code&gt; is called with an
empty object (let&amp;rsquo;s call it &lt;code&gt;o&lt;/code&gt;) as its context&lt;/li&gt;
&lt;li&gt;&lt;code&gt;o&lt;/code&gt; is given a &lt;code&gt;foo&lt;/code&gt; property with a value &lt;code&gt;&#39;bar&#39;&lt;/code&gt; (we wrote that ourselves)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;o&lt;/code&gt; is given a &lt;code&gt;constructor&lt;/code&gt; property. The value is a reference to
function &lt;code&gt;A&lt;/code&gt; (that&amp;rsquo;s automatically handled for us)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;o&lt;/code&gt; is returned (automatically handled for us) and referenced through a variable &lt;code&gt;a&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;on line 3 we define a &lt;code&gt;baz&lt;/code&gt; property on &lt;code&gt;A&lt;/code&gt;&amp;rsquo;s &lt;code&gt;prototype&lt;/code&gt; property&lt;/li&gt;
&lt;li&gt;on line 4 here are the steps to access &lt;code&gt;baz&lt;/code&gt; property via &lt;code&gt;a.baz&lt;/code&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;a&lt;/code&gt; points to an anonymous object &lt;code&gt;o&lt;/code&gt;, which does not have a &lt;code&gt;baz&lt;/code&gt; property&lt;/li&gt;
&lt;li&gt;&lt;code&gt;o&lt;/code&gt; has a &lt;code&gt;constructor&lt;/code&gt; property which points to &lt;code&gt;A&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;A&lt;/code&gt; has a &lt;code&gt;prototype&lt;/code&gt; property which points to an anonymous object &lt;code&gt;o2&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;o2&lt;/code&gt; has a &lt;code&gt;baz&lt;/code&gt; property which points to the string &lt;code&gt;&#39;blah&#39;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;type-introspection&#34;&gt;Type Introspection&lt;/h3&gt;
&lt;p&gt;There are 3 ways to instrospect into an object&amp;rsquo;s &amp;ldquo;type&amp;rdquo;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;typeof object === typeStr&lt;/code&gt;. Limitation: &lt;code&gt;typeStr&lt;/code&gt; is limited to strings
representing built-in types like &lt;code&gt;&#39;function&#39;&lt;/code&gt;, &lt;code&gt;&#39;object&#39;&lt;/code&gt;, &lt;code&gt;&#39;number&#39;&lt;/code&gt;,
&lt;code&gt;&#39;string&#39;&lt;/code&gt;, etc&lt;/li&gt;
&lt;li&gt;&lt;code&gt;object instanceof ConstructorFunction&lt;/code&gt;. Limitation: you need a reference to
&lt;code&gt;ConstructorFunction&lt;/code&gt; and it&amp;rsquo;s not guaranteed that &lt;code&gt;ConstructorFunction&lt;/code&gt;
was used to instantiate &lt;code&gt;object&lt;/code&gt;. It could be higher up in the prototype
chain.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;object.constructor === ConstructorFunction&lt;/code&gt;. That&amp;rsquo;s the most robust way to
check where an object comes from. This necessitates a reference to
&lt;code&gt;ConstructorFunction&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;achieving-inheritance-with-prototypes&#34;&gt;Achieving Inheritance With Prototypes&lt;/h3&gt;
&lt;p&gt;Achieving inheritance in JavaScript is as simple as using the prototype chain
lookup to our advantage so that &amp;ldquo;inherited&amp;rdquo; properties will be resolved
correctly, thus extending an object&amp;rsquo;s capabilities.&lt;/p&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
    function B() {
        this.dataB = function() {...};
    };
    B.prototype.functionB = function() {...};

    function A() {
        this.functionA = function() {...};
    };
    A.prototype = new B();

    var a = new A();

    a.functionA(); // ok
    a.functionB(); // ok!
    a instanceof A; // ok
    a instanceof B; // ok!
&lt;/pre&gt;
&lt;p&gt;Let&amp;rsquo;s go through what happens when we call &lt;code&gt;a.functionB()&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;a&lt;/code&gt; refers to an object (returned from &lt;code&gt;new A()&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;that object doesn&amp;rsquo;t have a &lt;code&gt;functionB&lt;/code&gt; property&lt;/li&gt;
&lt;li&gt;that object does have a &lt;code&gt;constructor&lt;/code&gt; property, pointing to &lt;code&gt;A&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;A&lt;/code&gt; has a &lt;code&gt;prototype&lt;/code&gt; property, pointing to an object (returned from &lt;code&gt;new B()&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;that object does not have a &lt;code&gt;functionB&lt;/code&gt; property&lt;/li&gt;
&lt;li&gt;that object does have a &lt;code&gt;constructor&lt;/code&gt; property, pointing to &lt;code&gt;B&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;B&lt;/code&gt; has a &lt;code&gt;prototype&lt;/code&gt; property, pointing to an object&lt;/li&gt;
&lt;li&gt;that object has a &lt;code&gt;functionB&lt;/code&gt; property. BINGO!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here&amp;rsquo;s the complete reference chain:&lt;br&gt;
&lt;code&gt;a&lt;/code&gt;-&amp;gt;&lt;code&gt;(new A())&lt;/code&gt;-&amp;gt;&lt;code&gt;constructor&lt;/code&gt;-&amp;gt;&lt;code&gt;A&lt;/code&gt;-&amp;gt;&lt;code&gt;prototype&lt;/code&gt;&lt;br&gt;
-&amp;gt;&lt;code&gt;(new B())&lt;/code&gt;-&amp;gt;&lt;code&gt;constructor&lt;/code&gt;-&amp;gt;&lt;code&gt;B&lt;/code&gt;-&amp;gt;&lt;code&gt;prototype&lt;/code&gt;-&amp;gt;&lt;code&gt;functionB&lt;/code&gt;&lt;/p&gt;
&lt;h3 id=&#34;gotchas-and-tricks&#34;&gt;Gotchas And Tricks&lt;/h3&gt;
&lt;p&gt;Prototypes come with lots of bold warnings, the first of which is: be extra
careful when modifying/extending native objects&#39; prototypes!&lt;br&gt;
There is only one &lt;code&gt;Array.prototype&lt;/code&gt; for a whole page. Be aware that modifying
it is similar to modifying a global variable. Actually it&amp;rsquo;s probably worse
because a lot of places are using &lt;code&gt;Array.prototype&lt;/code&gt; in non-explicit ways.&lt;/p&gt;
&lt;p&gt;In most browsers you can access native DOM element prototype and play with it:&lt;/p&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
    HTMLElement.prototype.addEventListener = function(type, fn, useProp) {
        console.log(&#39;trooooooll!&#39;); // don&#39;t do that, seriously!
    };
&lt;/pre&gt;
&lt;p&gt;Second gotcha: use &lt;code&gt;hasOwnProperty&lt;/code&gt; to loop through object&amp;rsquo;s properties.&lt;br&gt;
Otherwise you&amp;rsquo;ll loop through non-instance properties:&lt;/p&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
    Object.prototype.foo = 42;
    var obj = {a: 1, b: 2};

    for (var i in obj) { console.log(i); } 
    //-&gt; logs &#39;a&#39;, &#39;b&#39; *and &#39;foo&#39;*

    for (var i in obj) { if (obj.hasOwnProperty(i)) { console.log(i); } }
    //-&gt; logs &#39;a&#39; and &#39;b&#39;
&lt;/pre&gt;
&lt;p&gt;Trick to ensure a function is always invoked as a constructor:&lt;/p&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
    function A() {
        if (!(this instanceof arguments.callee)) {
            return new A();
        }
        this.foo = &#39;bar&#39;;
    };
&lt;/pre&gt;
&lt;h2 id=&#34;timers&#34;&gt;Timers&lt;/h2&gt;
&lt;p&gt;JavaScript is &lt;em&gt;single-threaded&lt;/em&gt;. That&amp;rsquo;s really important to understand. Once
you grasp the fact that the browser has no choice but to queue handlers when
events are firing at the same time, understanding why timers cannot be reliable
is easy.&lt;/p&gt;
&lt;p&gt;Browser APIs are well known: &lt;code&gt;window.setTimeout&lt;/code&gt; and &lt;code&gt;window.setInterval&lt;/code&gt; to
create timers, &lt;code&gt;window.clearTimeout&lt;/code&gt; and &lt;code&gt;window.clearInterval&lt;/code&gt; to clear them.&lt;/p&gt;
&lt;p&gt;Nifty trick for all browsers and IE &amp;gt; 9: timer functions can take arguments!
Like so:&lt;br&gt;
&lt;code&gt;window.setInterval(myfunction, 100, arg1, arg2)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Important note! There&amp;rsquo;s a difference between:&lt;/p&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
    # Executes `fn` every 10ms by calling setInterval once
    window.setInterval(fn, 10);
&lt;/pre&gt;
&lt;p&gt;and:&lt;/p&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
    # Executes `fn` every 10ms by calling setTimeout over and over
    window.setTimeout(function fn() {
        window.setTimeout(fn, 10)
    }, 10);
&lt;/pre&gt;
&lt;p&gt;Second version is guaranteed to run every 10ms or more.&lt;br&gt;
First version will try to execute every 10ms regardless of what happened before.&lt;/p&gt;
&lt;p&gt;Cutting expensive computation into manageable chunks is an interesting
application of timers. Instead of doing a 100% of the work in a big chunk you
can choose to schedule manageable chunk via &lt;code&gt;setTimeout&lt;/code&gt; thus enabling the
browser to do some work after each chunk finishes and before the next one
begins. Say a click event happens during a computation: the browser would get
a chance to execute the associated handler right after the current chunk is
done as opposed to waiting until the end of the whole computation.&lt;/p&gt;
&lt;p&gt;Timers are also super useful to build asynchronous test suites and centralized
timers.&lt;br&gt;
The idea is to have a single timer handling a queue (of tests to run or of
animations/functions to execute) so that the browser is not overwhelmed by
multiple timers. This centralized timer technique guarantees order of
execution. That&amp;rsquo;s a perk we don&amp;rsquo;t get when we use multiple native timers.&lt;/p&gt;
&lt;h2 id=&#34;cross-browser-strategies&#34;&gt;Cross Browser Strategies&lt;/h2&gt;
&lt;p&gt;Authoring cross-browser JavaScript is hard. Resig names 5 major concerns:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Browser bugs&lt;/li&gt;
&lt;li&gt;Browser bug fixes&lt;/li&gt;
&lt;li&gt;Missing browser features&lt;/li&gt;
&lt;li&gt;External code&lt;/li&gt;
&lt;li&gt;Browser regressions&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Some strategies/advices to deal with browser bugs/differences:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;encapsulate your code into its own closure/unit, expose it as little as possible&lt;/li&gt;
&lt;li&gt;degrade gracefully when features aren&amp;rsquo;t available and/or bugs arise&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Safe cross-browser fixes&amp;rdquo;: no feature detection, no side effects. Example:
ignoring negative width/height value: &lt;code&gt;if ((key == &#39;width&#39; || key == &#39;height&#39;) &amp;amp;&amp;amp; parseFloat(value) &amp;lt; 0) { value = undefined; }&lt;/code&gt;. This makes the
buggy browser&amp;rsquo;s API comply with the standard. It&amp;rsquo;s a Good Thing ®&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Object detection&amp;rdquo;: feature detection by inspecting a property/value of an
object. Example: bind event with W3C&amp;rsquo;s &lt;code&gt;addEventListener&lt;/code&gt; vs Microsoft&amp;rsquo;s
&lt;code&gt;attachEvent&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Feature simulation&amp;rdquo;: create and execute a reduced test case to isolate the
buggy behavior. That creates a toggle to work around the bug in our code.
Very often that feature simulation is executed once at load time to minimize
performance impact.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Interestingly enough Resig gives a list of &amp;ldquo;untestable&amp;rdquo; browser issues:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Event handler bindings (no way to determine if a handler has been bound or not)&lt;/li&gt;
&lt;li&gt;Event firing (no way to check if an event has been or will fire)&lt;/li&gt;
&lt;li&gt;CSS property effects (does it affect appearance)&lt;/li&gt;
&lt;li&gt;Browser crashes (if a feature makes the browser crash, feature simulation will too)&lt;/li&gt;
&lt;li&gt;API performance (prohibitively expensive to test)&lt;/li&gt;
&lt;li&gt;AJAX issues (tricky and expensive to test)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;dom-attributes-and-properties&#34;&gt;DOM Attributes and Properties&lt;/h2&gt;
&lt;p&gt;There is an incredible amount of quirks involved in getting/setting DOM
attributes and properties. Ways to get properties/attributes of DOM nodes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;elem.propertyName&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;elem.getAttribute(&#39;attributeName&#39;)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;elem.getAttributeNode(&#39;attributeName&#39;).nodeValue&lt;/code&gt; (recommanded way to get
the unaltered value)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Note that attribute and property names aren&amp;rsquo;t always the same. For instance
&lt;code&gt;class&lt;/code&gt; is a valid attribute name but the associated property is &lt;code&gt;className&lt;/code&gt;
The other ones are &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;readonly&lt;/code&gt;, &lt;code&gt;maxlength&lt;/code&gt;, &lt;code&gt;cellspacing&lt;/code&gt;, &lt;code&gt;rowspan&lt;/code&gt;,
&lt;code&gt;colspan&lt;/code&gt;, &lt;code&gt;tabindex&lt;/code&gt; which match respectively to the property names &lt;code&gt;htmlFor&lt;/code&gt;,
&lt;code&gt;readOnly&lt;/code&gt;, &lt;code&gt;maxLength&lt;/code&gt;, &lt;code&gt;cellSpacing&lt;/code&gt;, &lt;code&gt;rowSpan&lt;/code&gt;, &lt;code&gt;colSpan&lt;/code&gt;, &lt;code&gt;tabIndex&lt;/code&gt;.)&lt;/p&gt;
&lt;p&gt;Major quirks pointed out:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Form input&amp;rsquo;s &lt;code&gt;id&lt;/code&gt;/&lt;code&gt;name&lt;/code&gt; attributes are transferred on the form DOM node as
properties.  For instance if you have an input element with an &lt;code&gt;id&lt;/code&gt;/&lt;code&gt;name&lt;/code&gt;
attribute set to &lt;code&gt;foo&lt;/code&gt;, &lt;code&gt;myForm.foo&lt;/code&gt; will yield a reference this input.  Now
let&amp;rsquo;s say you have an input with its &lt;code&gt;name&lt;/code&gt;/&lt;code&gt;id&lt;/code&gt; attribute set to &lt;code&gt;action&lt;/code&gt;.
See the problem? Form element&amp;rsquo;s original &lt;code&gt;action&lt;/code&gt; property will be lost :/&lt;/li&gt;
&lt;li&gt;&lt;code&gt;href&lt;/code&gt;, &lt;code&gt;src&lt;/code&gt; or &lt;code&gt;action&lt;/code&gt; perform URL normalization (you get a full canonical
URL when you might expect a relative URL)&lt;/li&gt;
&lt;li&gt;input &lt;code&gt;type&lt;/code&gt; attribute can&amp;rsquo;t be changed after DOM node is inserted (IE only)&lt;/li&gt;
&lt;li&gt;more problems around the &lt;code&gt;style&lt;/code&gt; attribute: measuring &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt;,
getting color, opacity or pixel measures. One interesting API:
&lt;code&gt;getComputedStyle&lt;/code&gt; (or IE&amp;rsquo;s &lt;code&gt;currentStyle&lt;/code&gt;). It gives you the active CSS
property/value pairs for an element.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;understanding-event-propagation&#34;&gt;Understanding Event Propagation&lt;/h2&gt;
&lt;p&gt;The order in which events are triggered throughout the DOM tree is not
consistent across browsers.&lt;/p&gt;
&lt;p&gt;Netscape implements event propagation &amp;ldquo;outside-in&amp;rdquo;. An event propagates
from the root of the DOM tree all the way through its target (a button on which
you clicked for instance). This event propagation model is referred to as
&lt;strong&gt;capturing&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;IE implements it in the exact opposite way: &amp;ldquo;inside-out&amp;rdquo;. An event
propagates from the target element up to the DOM tree&amp;rsquo;s root. This event
propagation model is referred to as &lt;strong&gt;bubbling&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When the W3C had to choose, they didn&amp;rsquo;t. Instead W3C&amp;rsquo;s model lets you register
handlers for capturing or bubbling phase.&lt;br&gt;
Concretely, compliant browsers will do the following when an event is triggered:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;start at DOM tree&amp;rsquo;s root node. See if there are handlers set for &lt;strong&gt;capturing phase&lt;/strong&gt; for our event type. If yes, call them.&lt;/li&gt;
&lt;li&gt;go down one level in the tree, do the same (check and call potential handlers set for capturing)&lt;/li&gt;
&lt;li&gt;go down one more level, do the same&lt;/li&gt;
&lt;li&gt;&amp;hellip;etc&amp;hellip; (do the same and go down until we reach our event&amp;rsquo;s target)&lt;/li&gt;
&lt;li&gt;on the event&amp;rsquo;s target (i.e.,the button we clicked) check and call potential handlers set for capturing&lt;/li&gt;
&lt;li&gt;on the event&amp;rsquo;s target, see if there are handlers set for &lt;strong&gt;bubbling phase&lt;/strong&gt; for out event type. If yes, call them.&lt;/li&gt;
&lt;li&gt;go up one level in the tree, do the same (check and call potential handlers set for bubbling)&lt;/li&gt;
&lt;li&gt;go up one more level, do the same&lt;/li&gt;
&lt;li&gt;&amp;hellip;etc&amp;hellip; (do the same and go up until we reach the DOM tree&amp;rsquo;s root)&lt;/li&gt;
&lt;li&gt;on DOM tree&amp;rsquo;s root node, check and call potential handlers set for bubbling&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The standard API &lt;code&gt;elem.addEventListener(type, handler, useCapture)&lt;/code&gt; has 3
params. First one is the type of event to listen to (&amp;lsquo;click&amp;rsquo;, &amp;lsquo;focus&amp;rsquo;, etc),
second is the handler we want to trigger when the type of event we&amp;rsquo;re listening
to happens. The third parameter &lt;code&gt;useCapture&lt;/code&gt; is the propagation phase we&amp;rsquo;re interested in.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;if set to &lt;code&gt;false&lt;/code&gt;, your handler will be called during the bubbling phase (step 6 through 10)&lt;/li&gt;
&lt;li&gt;if set to &lt;code&gt;true&lt;/code&gt;, your handler will be called during the capturing phase (step 1 through 5)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;useCapture&lt;/code&gt; defaults to &lt;code&gt;false&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Another important thing to consider: browsers have hooks to stop event
propagation at any point. Inside a handler, &lt;code&gt;e.stopPropagation()&lt;/code&gt; and
&lt;code&gt;e.cancelBubble = true;&lt;/code&gt; (in IE) will do just that.&lt;/p&gt;
&lt;p&gt;That was a lengthy explanation but I think it describes what happens fairly
accurately. I hope that it will help you understand a few things. Namely:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;addEventListener(&#39;click&#39;, handler, false)&lt;/code&gt; will have consistent behavior in
IE and modern browsers out-of-the-box (remember, IE&amp;rsquo;s model only supports
bubbling phase). &lt;strong&gt;That&amp;rsquo;s why jQuery won&amp;rsquo;t let you set register handlers for
capturing phase&lt;/strong&gt;. Letting you doing do wouldn&amp;rsquo;t be cross-browser compatible.
jQuery supports bubbling in a cross browser fashion by emulating bubbling. In
browsers that don&amp;rsquo;t support it, the library manually walks the DOM tree up to
call registered handlers. That&amp;rsquo;s also how jQuery goes about supporting custom
events (&lt;code&gt;someJqueryElem.bind(&#39;my-custom-event&#39;, handler)&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;document.addEventListener(type, handler)&lt;/code&gt; is a catch-all that will run
&lt;strong&gt;after&lt;/strong&gt; every handler for this type in the path Root-Target has executed.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;document.addEventListener(type, handler, true)&lt;/code&gt; is a catch-all that will run
&lt;strong&gt;before&lt;/strong&gt; every handler for this type of event in the path Root-Target
executes.&lt;/li&gt;
&lt;li&gt;use &lt;code&gt;stopPropagation&lt;/code&gt; and &lt;code&gt;cancelBubble = true&lt;/code&gt; with &lt;strong&gt;extreme caution&lt;/strong&gt;.
When you do that you&amp;rsquo;re effectively preventing other handlers scheduled
to run after you from doing so.&lt;/li&gt;
&lt;li&gt;when registering multiple handlers on the same element for the same event
type, order &lt;strong&gt;is not guaranteed&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A good page to help you understand that if the explanation above didn&amp;rsquo;t stick:
&lt;a href=&#34;http://www.quirksmode.org/js/events_order.html&#34;&gt;Quirksmode On Events&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;jquerys-event-system&#34;&gt;jQuery&amp;rsquo;s Event System&lt;/h2&gt;
&lt;p&gt;At its core jQuery&amp;rsquo;s event system doesn&amp;rsquo;t rely much on the browser to work.
There are so many quirks that jQuery had to came up with a solution to
implement event binding, unbinding and triggering in a consistent manner.&lt;br&gt;
Key ideas:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the only handler actually registered by jQuery is a dispatcher. There is one
dispatcher per event type.&lt;/li&gt;
&lt;li&gt;to keep track of individual handlers, each DOM element is given a &lt;code&gt;data&lt;/code&gt;
property. Concretely it&amp;rsquo;s a mapping of event type to an array of handler for
that type.&lt;/li&gt;
&lt;li&gt;a dispatcher is responsible for looking at a DOM&amp;rsquo;s data store and calling
handlers if it finds handlers registered for its type (remember, there is one
dispatcher per event type).&lt;/li&gt;
&lt;li&gt;thus registering/unregistering a handler becomes equivalent to &amp;ldquo;add/remove a
function to a DOM&amp;rsquo;s data store&amp;rdquo;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is really clever because it enables inventory of handlers at any point in
time and programmatic triggering of registered handler.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;re interested in the nitty-gritty details head to &lt;a href=&#34;https://github.com/jquery/jquery/blob/master/src/event.js&#34;&gt;jQuery&amp;rsquo;s
source&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;concept-of-event-delegation&#34;&gt;Concept Of Event Delegation&lt;/h2&gt;
&lt;p&gt;jQuery&amp;rsquo;s &lt;code&gt;.delegate(type, selector, handler)&lt;/code&gt; (or &lt;code&gt;.on(type, selector, handler)&lt;/code&gt; in later versions) seems really magic if you don&amp;rsquo;t understand
the concept of event delegation.&lt;/p&gt;
&lt;p&gt;To put it in simple terms: &lt;strong&gt;event delegation is the process of registering a
handler high up in the DOM tree to handle events happening at lower levels.&lt;/strong&gt;&lt;br&gt;
Event delegation is made possible by 2 things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;event bubbling&lt;/li&gt;
&lt;li&gt;ability to inspect event object&amp;rsquo;s &lt;code&gt;target&lt;/code&gt; property in handlers&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Concretely, instead of just doing some work, a delegated handler will &lt;strong&gt;check
the target first&lt;/strong&gt; and &lt;strong&gt;then&lt;/strong&gt; do some work:&lt;/p&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
    var doWork = function() { console.log(&#39;did some work&#39;); }
    var button = document.findElementsByClassName(&#39;a-button&#39;)[0];

    // NON-DELEGATED version (the handler is bound directly)
    button.addEventListener(&#39;click&#39;, doWork, false); // use bubbling

    // DELEGATED version (we&#39;re checking the target first)
    document.addEventListener(&#39;click&#39;, function(e) {
        if (e.target.className === &#39;a-button&#39;) { // &lt;== &#34;Target check&#34;
            doWork();
        }
    }, false); // use bubbling too
&lt;/pre&gt;
&lt;p&gt;The delegated version above has several advantages:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a button with class &amp;lsquo;a-button&amp;rsquo; can be inserted in the DOM &lt;strong&gt;after&lt;/strong&gt; we
perform event binding. It&amp;rsquo;s crucial if you&amp;rsquo;re inserting content after an XHR
request for instance&lt;/li&gt;
&lt;li&gt;multiple buttons with a class &amp;lsquo;a-button&amp;rsquo; could be on the page, things will
just work. This is awesome if you have behavior that you want to attach to a
big number of elements. Say you want to have JS behavior for all cells of a
HUGE table. Instead of looping through all the elements to bind a handler to
each and every one of those cells you can use delegation to bind a single
handler to a common container (the containing &lt;code&gt;&amp;lt;table&amp;gt;&lt;/code&gt; element for instance)&lt;/li&gt;
&lt;li&gt;hey we&amp;rsquo;re not bound to just buttons anymore! Every element on page that
satisfies our target check gets to trigger &lt;code&gt;doWork&lt;/code&gt; when clicked on.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Of course jQuery is more sophisticated and lets you delegate your handler on a
container by specifying a &lt;em&gt;jQuery selector&lt;/em&gt;. Under the hoods jQuery will check
if the event target matches this jQuery selector. If it does your handler will
be called.&lt;/p&gt;
&lt;h2 id=&#34;dom-manipulation&#34;&gt;DOM Manipulation&lt;/h2&gt;
&lt;p&gt;DOM manipulations are expensive. Libraries such as jQuery do a very good job of
thinking about performance which is why relying on an abstraction to manipulate
the DOM makes sense (manipulating the DOM yourself would most likely result in
your app being slow and leaking memory). For instance you&amp;rsquo;re very unlikely to
use methods such as &lt;code&gt;createDocumentFragment&lt;/code&gt; if you&amp;rsquo;re authoring a one-off DOM
manipulation.&lt;/p&gt;
&lt;p&gt;Steps to implement DOM insertion correctly:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Parse the string into a HTML string&lt;/em&gt;: no surprise there, pretty much What you
would expect: regular expression, yadda, yadda, yadda.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Create HTML nodes from the HTML string&lt;/em&gt;: that step has to go around the fact
that certain elements have to be created within a specific element in order
to be inserted in the DOM successfully. For instance, &lt;code&gt;&amp;lt;td&amp;gt;&lt;/code&gt; must be withing
a &lt;code&gt;&amp;lt;tr&amp;gt;&lt;/code&gt;, which must be within a &lt;code&gt;&amp;lt;tbody&amp;gt;&lt;/code&gt; which must be withing a &lt;code&gt;&amp;lt;table&amp;gt;&lt;/code&gt;.
To go around those restrictions, the HTML string is wrapped before insertion,
elements are inserted in an empty div (using &lt;code&gt;innerHTML&lt;/code&gt;), and used from there.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Insert those nodes into the document&lt;/em&gt;: straightforward, except for the fact
that you have to deal with inline scripts potentially contained in the
collection of DOM nodes you&amp;rsquo;re about to insert in the page. Workaround is to
delete &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; nodes from the inserted nodes and execute them
individually by inserting and removing them immediately after the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;
tag.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Removing&lt;/em&gt; elements is tricky because you have to be careful to remove the
associated handlers not to create memory leaks.&lt;br&gt;
Cloning elements is difficult in IE because IE copies not only the DOM node
but also event handlers (heh.)&lt;/p&gt;
&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion?&lt;/h2&gt;
&lt;p&gt;If you found this article useful I highly recommend the full book,
&lt;a href=&#34;http://www.manning.com/resig/&#34;&gt;Secrets Of The JavaScript Ninja&lt;/a&gt;. I personally
found the book super useful and illuminating in a lot of ways.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s good to be able to read about &amp;ldquo;real-world&amp;rdquo; JavaScript, including about
browser quirks, language pitfalls and testing.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>UIUC Tech Talk On Modern Web Debugging</title>
      <link>https://arnaudbrousseau.com/notes/uiuc-tech-talk.html</link>
      <pubDate>Thu, 10 Oct 2013 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/uiuc-tech-talk.html</guid>
      <description>&lt;p&gt;I went to UIUC in October 2013 to meet students and tell them about Yelp
engineering opportunities. I took advantage of this opportunity to put together
some slides to give a talk about modern Web debugging.&lt;/p&gt;
&lt;p&gt;As a Web developer this is hands down the domain in which I feel I&amp;rsquo;ve made the
most progress. Turns out being better at debugging makes you a lot more
productive too!&lt;/p&gt;
&lt;p&gt;I talked about a whole bunch of things including: how to use a Web console, how
to chase down a bug in HTML, CSS or JS, how to write unit test in pure JS and
integration test in Selenium (with demos). I also touched on what test
automation tools were (mocha, buildbot, travisCI, etc.)&lt;/p&gt;
&lt;p&gt;Interested in the slides?
&lt;a href=&#34;https://docs.google.com/a/yelp.com/presentation/d/1ng20bCc6ChlkRMPoycbivLM_fASvb4l4CmwTKv3WoKM/present&#34;&gt;They&amp;rsquo;re online&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;If you want to know more, checkout the &lt;a href=&#34;https://github.com/ArnaudBrousseau/uiuc_tech_talk&#34;&gt;git
repo&lt;/a&gt;, it contains
everything including the demos, slides and code examples.&lt;/p&gt;
&lt;p&gt;And here&amp;rsquo;s a picture of that room full of UIUC students:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://arnaudbrousseau.com/img/uiuc_tech_talk.jpg&#34; alt=&#34;Room before beginning the talk&#34;&gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;3&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Playing with Firefly and Fitbit data</title>
      <link>https://arnaudbrousseau.com/notes/playing-with-firefly-and-fitbit-data.html</link>
      <pubDate>Sun, 21 Oct 2012 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/playing-with-firefly-and-fitbit-data.html</guid>
      <description>&lt;h2 id=&#34;initial-idea&#34;&gt;Initial idea&lt;/h2&gt;
&lt;p&gt;Plot Fitbit data using Firefly, a plotting library recently open sourced by Yelp.&lt;/p&gt;
&lt;h2 id=&#34;install-steps&#34;&gt;Install steps&lt;/h2&gt;
&lt;p&gt;As of now, the install process is still a bit rough, but nothing you can&amp;rsquo;t get away with.&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
    git clone https://github.com/Yelp/firefly.git
    git submodule update --init
    sudo easy_install tornado
    sudo easy_install pyyaml
    sudo easy_install simplejson
    sudo easy_install tornado
&lt;/pre&gt;
&lt;p&gt;And then, you need to install RDDTool. This library is a pain to install if
you&amp;rsquo;re on MAC OS X. Here&amp;rsquo;s what I did:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Go to &lt;a href=&#34;http://www.macports.org/install.php#pkg&#34;&gt;http://www.macports.org/install.php#pkg&lt;/a&gt; and download the version that suits your OS X version&lt;/li&gt;
&lt;li&gt;Install mac port&lt;/li&gt;
&lt;li&gt;run &amp;ldquo;sudo port install rrdtool&amp;rdquo;. This will take care of all the dependancies not installed on your system&lt;/li&gt;
&lt;li&gt;sudo port build rrdtool, which will give you a build version&lt;/li&gt;
&lt;li&gt;&lt;code&gt;cd /opt/local/var/macports/build/*_net_rrdtool/rrdtool/work/rrdtool-1.4.7/bindings/python/&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;sudo /opt/local/bin/python setup.py build&lt;/li&gt;
&lt;li&gt;sudo /opt/local/bin/python setup.py install&lt;/li&gt;
&lt;li&gt;sudo port install rrdtool&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Once that&amp;rsquo;s done, you can hopefully run Firefly with the following:&lt;/p&gt;
&lt;pre class=&#34;brush:plain&#34;&gt;
  python -m firefly.main --testing -c firefly.yaml.example
&lt;/pre&gt;
&lt;p&gt;I personnaly had issues with the python version I was running. If you&amp;rsquo;re in some
trouble see this SO thread: &lt;a href=&#34;http://stackoverflow.com/questions/12658141/python-cannot-import-urandom-module-os-x&#34;&gt;http://stackoverflow.com/questions/12658141/python-cannot-import-urandom-module-os-x&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;troubles&#34;&gt;Troubles&lt;/h2&gt;
&lt;p&gt;The value returned by &lt;code&gt;socket.getfqdn()&lt;/code&gt; was awfully wrong for me. I had to
hardcode stuff in main.(&lt;code&gt;firefly/main.py&lt;/code&gt;)&lt;br&gt;
Also, even after doing that, the json encoding in the index template would
cause everything to fail once again. I had to harcode things again there.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Working Efficiently With Legacy Code</title>
      <link>https://arnaudbrousseau.com/notes/working-efficiently-with-legacy-code.html</link>
      <pubDate>Sun, 02 Sep 2012 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/working-efficiently-with-legacy-code.html</guid>
      <description>&lt;p&gt;This is my summary of the book &amp;ldquo;Working Effectively with Legacy Code&amp;rdquo; by
Michael C. Feathers.&lt;/p&gt;
&lt;h2 id=&#34;gist-of-the-book&#34;&gt;Gist of the book&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Legacy code is untested code.&lt;br&gt;
Bad code is untested code.&lt;br&gt;
Even good, untested code is bad code.&lt;br&gt;
Write tests. Write code. Write more tests. Write more code. Write more tests.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Did you say TDD?&lt;/p&gt;
&lt;p&gt;Yes, this book is about tests. It introduces some vocabulary to talk about tests, then actually talk about tests by looking at specific use cases. It specifically looks at legacy use cases, where putting a piece of code under test can lead to a lot of stress.&lt;/p&gt;
&lt;h2 id=&#34;introduction-to-new-concepts&#34;&gt;Introduction to new concepts&lt;/h2&gt;
&lt;p&gt;If you&amp;rsquo;re new to TDD, and if you&amp;rsquo;re never written tests before you probably
have some catchup to do on vocabulary. This book introduces those potentially
new concept pretty well.&lt;/p&gt;
&lt;h3 id=&#34;test-harness&#34;&gt;Test harness&lt;/h3&gt;
&lt;p&gt;A test harness is a piece of code written to exercice some piece of software.&lt;/p&gt;
&lt;h3 id=&#34;sensing&#34;&gt;Sensing&lt;/h3&gt;
&lt;p&gt;Getting access to internals of a piece of software. Think about loop indexes
fot instance. Or internal state of an object. Things that you usually have to
print out in order to debug your program.&lt;/p&gt;
&lt;h3 id=&#34;fake-and-mock-objects&#34;&gt;Fake and mock objects&lt;/h3&gt;
&lt;p&gt;A fake object is an object to enable test harness. It basically exists in place
of a real object, for instance a DB connection.&lt;br&gt;
A mock object is a fake object containing assertions.&lt;/p&gt;
&lt;h3 id=&#34;seams&#34;&gt;Seams&lt;/h3&gt;
&lt;p&gt;A place where a program&amp;rsquo;s behavior can be changed without editing it.&lt;br&gt;
For instance:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;preprocessing seam&lt;/li&gt;
&lt;li&gt;link seam&lt;/li&gt;
&lt;li&gt;object seam
Every seam has an enabling point (classpath, call to a method, etc).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;pinch-points&#34;&gt;Pinch points&lt;/h3&gt;
&lt;p&gt;A pinch point is a point where tests can detect change in meny methods at the
same time.&lt;/p&gt;
&lt;h3 id=&#34;characterization-tests&#34;&gt;Characterization tests&lt;/h3&gt;
&lt;p&gt;Tests that describe the behavior of the piece of software in its harness.&lt;/p&gt;
&lt;h2 id=&#34;sprouts&#34;&gt;Sprouts&lt;/h2&gt;
&lt;p&gt;Sprouting refers to a technique aiming at extracting new behavior to a new
method (&amp;ldquo;sprout method&amp;rdquo;) or class (&amp;ldquo;sprout class&amp;rdquo;).&lt;/p&gt;
&lt;h2 id=&#34;wraps&#34;&gt;Wraps&lt;/h2&gt;
&lt;p&gt;Wrapping a method (&amp;ldquo;Wrap method&amp;rdquo;) or a class (&amp;ldquo;Wrap class&amp;rdquo;) refers to the
process of encapsulation or decoration to add new behavior to legacy code.&lt;/p&gt;
&lt;p&gt;In the case of the Wrap Method, the new behavior is implemented in a &lt;code&gt;new&lt;/code&gt;
method, and the old function calls the new one, so that new behavior will be
called by &lt;code&gt;old(new())&lt;/code&gt;.&lt;br&gt;
The Wrap Class is really similar: the new class inherits from the old one and
adds the new behavior required.&lt;/p&gt;
&lt;h2 id=&#34;dependency-inversion-principle&#34;&gt;Dependency inversion principle&lt;/h2&gt;
&lt;p&gt;Code should depend on interface, not implementation.&lt;/p&gt;
&lt;h2 id=&#34;openclosed-principle&#34;&gt;Open/Closed principle&lt;/h2&gt;
&lt;p&gt;A piece of code should be open for extension but closed for modification, which
basically means a good design doesn&amp;rsquo;t require to change much code: you just
have to write new code for a new feature.&lt;/p&gt;
&lt;h2 id=&#34;how-should-you-develop-a-new-feature&#34;&gt;How should you develop a new feature?&lt;/h2&gt;
&lt;p&gt;TDD + programming by difference (subclass and override behavior).&lt;br&gt;
Gotcha: &amp;ldquo;Liskov Substitution Principle&amp;rdquo; — avoid overiding concrete methods. The
ideal hierarchy is a hierarchy where no class overides one of its parents&#39;
methods. You can achieve that via abstract classes and inheritance from
interfaces instead.&lt;/p&gt;
&lt;h2 id=&#34;i-cant-get-this-class-into-a-test-harness&#34;&gt;I can&amp;rsquo;t get this class into a test harness&lt;/h2&gt;
&lt;p&gt;Extract interface and subclass into a test. That&amp;rsquo;s how you can get around
annoying params.&lt;/p&gt;
&lt;h2 id=&#34;i-cant-run-this-method-into-a-test-harness&#34;&gt;I can&amp;rsquo;t run this method into a test harness&lt;/h2&gt;
&lt;p&gt;First, ask yourself if you should run this method to begin with. You should
avoid testing private methods. Test public interfaces or make a private method
public if you really need to test it.&lt;br&gt;
Cheap solution to test a private method: make it protected and subclass.&lt;/p&gt;
&lt;h2 id=&#34;commandquery-separation-principle&#34;&gt;Command/Query separation principle&lt;/h2&gt;
&lt;p&gt;A &amp;ldquo;query&amp;rdquo; method is a method that has no side effect and returns a value.&lt;br&gt;
A &amp;ldquo;command&amp;rdquo; method is a method that has side effect and returns no value.&lt;/p&gt;
&lt;p&gt;The &amp;ldquo;Command/Query separation principle&amp;rdquo; simply dictates that a method
shouldn&amp;rsquo;t be a query and a command at the same time.&lt;/p&gt;
&lt;h2 id=&#34;finding-test-points&#34;&gt;Finding test points&lt;/h2&gt;
&lt;p&gt;Learning to reason about effects, draw effect stucture and find pinch points.
Make sure to include subclasses and other callers in the system to have a full
picture.&lt;/p&gt;
&lt;h2 id=&#34;i-dont-know-what-tests-to-write&#34;&gt;I don&amp;rsquo;t know what tests to write&lt;/h2&gt;
&lt;p&gt;If you&amp;rsquo;re working with legacy code, write characterization tests:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;aim for piece of logic, don&amp;rsquo;t hesitate to make use of sensing variables&lt;/li&gt;
&lt;li&gt;think about the responsabilities of your code and cber what can go wrong&lt;/li&gt;
&lt;li&gt;test extreme values of inputs&lt;/li&gt;
&lt;li&gt;try to look for and expose invariant&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;i-dont-understand-the-code-well-enough-to-change-it&#34;&gt;I don&amp;rsquo;t understand the code well enough to change it&lt;/h2&gt;
&lt;p&gt;If you don&amp;rsquo;t understand the code well enough, here are a couple of things you can try:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;print the code and try to make sense of it&lt;/li&gt;
&lt;li&gt;scratch refactoring: just experiment with refactoring the code, make it run&amp;hellip;but don&amp;rsquo;t commit!&lt;/li&gt;
&lt;li&gt;look for, and delete unused code&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;dealing-with-big-classes&#34;&gt;Dealing with big classes&lt;/h2&gt;
&lt;p&gt;The problem with big classes is that they tend to be confusing, not well-tested
(because they ARE a pain to test), and extremely hard to change since intance
variable can make any refactor affect the whole class.&lt;/p&gt;
&lt;h3 id=&#34;single-responsability-principle&#34;&gt;Single Responsability Principle&lt;/h3&gt;
&lt;p&gt;Every class should have a single responsibility: it should have a single
purpose in the system, and there should be only one reason to change it.&lt;/p&gt;
&lt;h3 id=&#34;heuristics-to-break-a-monster-class&#34;&gt;Heuristics to break a monster class&lt;/h3&gt;
&lt;p&gt;Several heuristics are listed in this chapter:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Group methods together. Look at names to give you hints about what methods
should go together. Try to look for instance var reuse&lt;/li&gt;
&lt;li&gt;Look at hidden methods (protected or private). They often indicate that
another class should emerge.&lt;/li&gt;
&lt;li&gt;Try to think of decisions that can change. This is a hard one, but try to see
hard-coded decisions in the class. Now make them configurable.&lt;/li&gt;
&lt;li&gt;Point out internal relations or isolations. Very often, instance variable are
used by parts of a class, but not by another.&lt;/li&gt;
&lt;li&gt;Describe the responsability of that monster class as a single sentence. Write
it as a comment at the top of the file, and cut what&amp;rsquo;s not relevant in
another class. Quite drastic.&lt;/li&gt;
&lt;li&gt;Scratch refactoring: let your imagination flow and edit some code. Don&amp;rsquo;t
commit.&lt;/li&gt;
&lt;li&gt;Focus on your work (new feature) and evaluate how this impacts this class&#39;
responsability. Hopefully you&amp;rsquo;ll see things through a new lens.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;interface-segregation-principle&#34;&gt;Interface Segregation Principle&lt;/h3&gt;
&lt;p&gt;When a class is really large, the other parts of the system interacting with it
rarely need to use all its methods at once. So we can use different groupings
of methods to &amp;ldquo;segregate&amp;rdquo; the clients. The way to do it is to define those
groupings as interface and make the monster class implement them all. That will
bring isolation between the large class and the rest of the system.&lt;/p&gt;
&lt;h2 id=&#34;dealing-with-big-methods&#34;&gt;Dealing with big methods&lt;/h2&gt;
&lt;p&gt;Big methods are kind of the same as big classes. They should be avoided because
monster methods are complex, confusing, hard to test and really difficult to
change.&lt;/p&gt;
&lt;p&gt;Two kinds of big methods out here: bulleted methods and snarled methos. A
bulleted method is a method having a flat structure. It&amp;rsquo;s basically saying: do
A, then do B, then do C, etc. Snarled methods are worst because they have
conditionals, and loops mixed in. Their structure is dominated by indented
blocks, which makes them far less readable.&lt;/p&gt;
&lt;h2 id=&#34;misc&#34;&gt;Misc&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;A &amp;ldquo;slow&amp;rdquo; test is a test that takes 0.1s to run or more.&lt;/li&gt;
&lt;li&gt;Abbreviations are okay when they&amp;rsquo;re used consistently, but they are generally
a bad idea. Try not to abbreviate when you can avoid it.&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    <item>
      <title>WTF is Nexus7 doing with devicePixelRatio?</title>
      <link>https://arnaudbrousseau.com/notes/nexus7-devicepixelratio-wtf.html</link>
      <pubDate>Tue, 24 Jul 2012 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/nexus7-devicepixelratio-wtf.html</guid>
      <description>&lt;h2 id=&#34;what-is-devicepixelratio&#34;&gt;What is devicePixelRatio?&lt;/h2&gt;
&lt;p&gt;&amp;ldquo;devicePixelRatio&amp;rdquo; is a JavaScript property used to determine the pixel density of a device.&lt;/p&gt;
&lt;h2 id=&#34;why-does-that-matter&#34;&gt;Why does that matter?&lt;/h2&gt;
&lt;p&gt;As a web developer working on a mobile product (disclaimer: I work for Yelp on
the mobile site team), I care a lot about how websites are displayed on mobile
devices.
Very often we fallback to JS to serve the best experience for each device, and
there are a couple of areas where JS is required if you want to take advantage
of the new display capabilities.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Responsive images
Example: &lt;a href=&#34;http://menacingcloud.com/?c=highPixelDensityDisplays&#34;&gt;http://menacingcloud.com/?c=highPixelDensityDisplays&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Canvas based interaction
&lt;a href=&#34;http://www.html5rocks.com/en/tutorials/canvas/hidpi/&#34;&gt;http://www.html5rocks.com/en/tutorials/canvas/hidpi/&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Many other reasons including image loading, browser height sniffing, etc.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;nexus7-what-did-you-do-buddy&#34;&gt;Nexus7: what did you do buddy?&lt;/h2&gt;
&lt;p&gt;Nexus7 reports a devicePixelRatio value of 1.3250000476837158. You read right.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Hacking San Francisco Hills</title>
      <link>https://arnaudbrousseau.com/notes/hacking-san-francisco-hills.html</link>
      <pubDate>Sun, 03 Jun 2012 00:00:00 +0000</pubDate>
      <guid>https://arnaudbrousseau.com/notes/hacking-san-francisco-hills.html</guid>
      <description>&lt;h2 id=&#34;so-what-are-we-building&#34;&gt;So What Are We Building?&lt;/h2&gt;
&lt;p&gt;I live in San Francisco. I like living in this city and I walk a lot. San
Francisco has a special feature: its hills. They can be as steep as 30% in
parts of the city.&lt;/p&gt;
&lt;p&gt;I find it pretty frustrating to look at Google Maps not knowing where the hills
are so I wanted an overlay that would color code street blocks according to
their steepness.&lt;/p&gt;
&lt;h2 id=&#34;first-idea-heatmap-of-elevation&#34;&gt;First Idea: Heatmap Of Elevation&lt;/h2&gt;
&lt;p&gt;My first idea to get the result I wanted was to retrieve the elevation of
all possible points in San Francisco to generate a heat map that I would
overlay on top of Google Maps. Google has a nifty feature that lets you use
Table Fusion to build Maps layers. However they won&amp;rsquo;t let you read more than
100,000 rows per request/layer.&lt;/p&gt;
&lt;p&gt;I wanted to cover the whole city. In other words, I wanted an evenly
distributed cloud of points within SF. To get the coordinates of the ~100,000
points I needed, I wrote a quick Python script:&lt;/p&gt;
&lt;pre class=&#34;brush: python&#34;&gt;
    ### SF City in a box?
    # 37.811038,-122.477778 &lt;= Northernmost point, Golden Gate Bridge
    # 37.778669,-122.514428 &lt;= Easternmost point, Cliff House near Ocean Beach
    # 37.704739,-122.442899 &lt;= Southernmost point, before San Bruno mountain park begins
    # 37.728731,-122.357017 &lt;= Westernmost point, at Hunters point
    from __future__ import division

    =====================

    &gt;&gt;&gt; max_lat = 37.811038
    &gt;&gt;&gt; min_lat = 37.704739
    &gt;&gt;&gt; min_lng = -122.514428
    &gt;&gt;&gt; max_lng = -122.357017

    =====================

    &gt;&gt;&gt; lat_step = (max_lat - min_lat) / 300
    0.0003543300000000234
    &gt;&gt;&gt; lng_step = (max_lng - min_lng) / 300
    0.0005247033333333206

    =====================

    &gt;&gt;&gt; lat_list = [min_lat + i*lat_step for i in range(301)]
    &gt;&gt;&gt; lng_list = [min_lng + i*lng_step for i in range(301)]
    &gt;&gt;&gt; lat_lng_pts = [(lat,lng) for lat in lat_list for lng in lng_list]

    &gt;&gt;&gt; len(lat_lng_pts)
    90601
&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;lat_lng_pts&lt;/code&gt; is the list of (latitude, longitude) we&amp;rsquo;re interested in. Next step: retrieve the altitude for every points we got. That&amp;rsquo;s where the USGS dataset comes in handy. The USGS API supports simple GETs. For instance:&lt;/p&gt;
&lt;pre class=&#34;brush: plain&#34;&gt;
    GET /xmlwebservices2/elevation_service.asmx/getElevation?X_Value=lng&amp;Y_Value=lat&amp;Elevation_Units=METERS&amp;Source_Layer=NED.CONUS_NED_13W&amp;Elevation_Only=TRUE HTTP/1.1
    Host: gisdata.usgs.net

    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length

    &lt;?xml version=&#34;1.0&#34;?&gt;
    &lt;double&gt;56.2435&lt;/double&gt;
&lt;/pre&gt;
&lt;p&gt;Now, &amp;ldquo;METERS&amp;rdquo; could be &amp;ldquo;FEET&amp;rdquo;, but I prefer the metric system so here you go.
The weird &amp;ldquo;NED.CONUS_NED_13W&amp;rdquo; param corresponds to the Western part of the US (see &lt;a href=&#34;http://gisdata.usgs.net/XMLWebServices2/Elevation_Service_Methods.php&#34; title=&#34;USGS Documentation&#34;&gt;this table&lt;/a&gt; for more possible params). And the &lt;code&gt;Elevation_only&lt;/code&gt; param tells that we care about the elevation only. The response will be a simple number, wrapped in XML.&lt;/p&gt;
&lt;p&gt;Now, back to our Python shell:&lt;/p&gt;
&lt;pre class=&#34;brush: python&#34;&gt;
    &gt;&gt;&gt; import urllib2, sys
    &gt;&gt;&gt; def scrape(lat_lng_pts, filename):
    &gt;&gt;&gt;   f = open(filename, &#34;a&#34;)
    &gt;&gt;&gt;   for (lat, lng) in lat_lng_pts:
    &gt;&gt;&gt;     resp = urllib2.urlopen(&#34;http://gisdata.usgs.net/xmlwebservices2/elevation_service.asmx/getElevation?X_Value=&#34; + str(lng) + &#34;&amp;Y_Value=&#34; + str(lat) + &#34;&amp;Elevation_Units=METERS&amp;Source_Layer=NED.CONUS_NED_13W&amp;Elevation_Only=TRUE&amp;Elevation_Only=TRUE&#34;)
    &gt;&gt;&gt;     data = resp.read()
    &gt;&gt;&gt;     elevation = data.split(&#34;&lt;double&gt;&#34;)[-1].split(&#34;&lt;/double&gt;&#34;)[0]
    &gt;&gt;&gt;     f.write(str(lat) + &#34;|&#34; + str(lng) + &#34;|&#34; + elevation + &#34;\n&#34;)
    &gt;&gt;&gt;     sys.stdout.write(&#34;.&#34;)
    &gt;&gt;&gt;   f.close()
    &gt;&gt;&gt; scrape(lat_lng_pts, &#34;elevation-data.csv&#34;)
    .
    .
    .
    === Some time passes by...actually, a few hours ===
    .
    .
    .
&lt;/pre&gt;
&lt;p&gt;Once I created the CSV, I imported it into a brand &lt;a href=&#34;https://www.google.com/fusiontables/DataSource?snapid=S556615xSvg&#34;&gt;new Google Fusion Table&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;A few tricks:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the longitude and latitude columns are set to &amp;ldquo;location&amp;rdquo; type, which enables
easier integration with Google Maps further down the road.&lt;/li&gt;
&lt;li&gt;don&amp;rsquo;t be afraid to delete and import the data again. Since Google Fusion
Table is kinda new, it can be buggy, especially with large datasets&lt;/li&gt;
&lt;li&gt;I deleted the bad points (various very negative elevations)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;What I originally envisioned was a heatmap-like visualization, where the high
areas would be red, while the lower ones would be green. It appears that
heatmaps are only possible with density data&amp;hellip;so&amp;hellip;no &lt;a href=&#34;https://developers.google.com/maps/documentation/javascript/layers#FusionTablesHeatmaps&#34;&gt;Fusion Table
Heatmaps&lt;/a&gt;
for me. Not this time.&lt;/p&gt;
&lt;p&gt;Plan B: use a standard &lt;a href=&#34;https://developers.google.com/maps/documentation/javascript/layers#FusionTables&#34;&gt;Fusion Table
layer&lt;/a&gt;,
with a custom, semi-transparent overlay to let the map shine through. Easy you
say?&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;http://code.google.com/p/fusion-tables/issues/detail?id=69&#34;&gt;Not quite&lt;/a&gt; (seems
I can&amp;rsquo;t have a transparent png as my custom marker). In this issue, there&amp;rsquo;s a
workaround which involves using the Fusion API directly, but I didn&amp;rsquo;t try it out.&lt;/p&gt;
&lt;p&gt;Say I somehow managed to make it work, the current approach has the following flaws:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The geocoded points aren&amp;rsquo;t aligned with the roads at all, which can be a
problem in some cases&lt;/li&gt;
&lt;li&gt;More importantly, the current visualization simply gives an idea of the
absolute elevation, which doesn&amp;rsquo;t tell if a street is steep or not.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The result I have so far is &lt;a href=&#34;https://arnaudbrousseau.com/labs/sf-hills/first-try.html&#34;&gt;not that
bad&lt;/a&gt;, but not what I have in
mind.&lt;/p&gt;
&lt;p&gt;Looks like a perfect time to step back to think again.&lt;/p&gt;
&lt;h2 id=&#34;a-new-battleplan&#34;&gt;A New Battleplan&lt;/h2&gt;
&lt;p&gt;I decided to stay within Google&amp;rsquo;s environment by leveraging the
&lt;a href=&#34;https://developers.google.com/maps/documentation/javascript/elevation&#34;&gt;Elevation&lt;/a&gt;
and &lt;a href=&#34;https://developers.google.com/maps/documentation/geocoding/&#34;&gt;Geocoding&lt;/a&gt;
APIs.&lt;/p&gt;
&lt;p&gt;The Geocoding API will transform information like &amp;ldquo;Market and 3rd, San
Francisco, CA&amp;rdquo; into (latitude, longitude) points. The elevation API will then
tell the elevation of a certain (lat, lng) point.&lt;/p&gt;
&lt;p&gt;This should give me a matrix of (alt, lng, elevation). Another advantage of the
&amp;ldquo;cross-street-only&amp;rdquo; approach: it will reduce the number of points we will work
with. We&amp;rsquo;ll have a 100x100 matrix, which gives us approximately 10,000 points
to work with, instead of 90,000 before.&lt;/p&gt;
&lt;p&gt;Finally, I&amp;rsquo;ll draw lines from one crossing to another using
&lt;a href=&#34;https://developers.google.com/maps/documentation/javascript/overlays#Polylines&#34;&gt;polylines&lt;/a&gt;.
They will be colored from green to red depending on how steep the current
street portion is.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s break down the problem into smaller bits:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Get the data about the street crossings in San Francisco. Since there&amp;rsquo;s no such data available directly, we&amp;rsquo;ll manually create a JSON file containing these.&lt;/li&gt;
&lt;li&gt;Take each crossing, geocode it, and retrieve the altitude.&lt;/li&gt;
&lt;li&gt;Compute the elevation difference between this crossing and it&amp;rsquo;s closest neighbors.&lt;/li&gt;
&lt;li&gt;Generate the polyline with the appropriate color, reflecting the steepness of the path&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Now that we have this battleplan, let&amp;rsquo;s proceed, step-by-step.&lt;/p&gt;
&lt;h2 id=&#34;gettin-the-data&#34;&gt;Gettin&#39; the data&lt;/h2&gt;
&lt;p&gt;I decided to go with a brute force approach. I statically declared all street
crossings in a file and ran a batch over it to retrieve the geocoordinate of a
crossing (via Google&amp;rsquo;s Geocoding API) and the elevation of those coordinates
via Google&amp;rsquo;s Elevation API.&lt;/p&gt;
&lt;p&gt;Static street crossing declaration looks like:&lt;/p&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
    var streetCrossings = {
      &#34;Lyon St&#34;: [&#34;Bay St&#34;, &#34;Francisco St&#34;, &#34;Chestnut St&#34;, &#34;Lombard St&#34;, &#34;Greenwich St&#34;, &#34;Filbert St&#34;, &#34;Union St&#34;, &#34;Green St&#34;], 
      &#34;Lyon St.&#34;: [
        &#34;Broadway&#34;, &#34;Pacific Ave&#34;, &#34;Jackson St&#34;, &#34;Washington St&#34;, &#34;Clay&#34;, &#34;Sacramento&#34;, &#34;California&#34;, &#34;Pine&#34;, &#34;Bush St&#34;, &#34;Sutter St&#34;, 
        &#34;Post St&#34;, &#34;Geary Blvd&#34;, &#34;O&#39;Farrell&#34;], 
      &#34;Lyon St..&#34;: [&#34;Turk St&#34;, &#34;Golden Gate Ave&#34;, &#34;Mc Allister St&#34;, &#34;Fulton St&#34;, &#34;Grove St&#34;, &#34;Hayes St&#34;, &#34;Fell St&#34;], 
      &#34;Lyon St...&#34;: [&#34;Oak St&#34;, &#34;Page St&#34;, &#34;Haight St&#34;], 
      ...etc...
    }
&lt;/pre&gt;
&lt;p&gt;Then I wrote the batch to geocode crossings and retrieve their elevation in JS.
It looks like this:&lt;/p&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
      // Geocode the address, and create a new marker and InfoWindow at the geocoded location
      function geocodeCrossing(streetY, streetX) {
        var address = streetY + &#39; and &#39; + streetX + &#39;, San Francisco, CA&#39;;
            lat=null, lng=null;

        console.log(&#39;Now geocoding: &#39; + address);

        geocoder.geocode( { &#39;address&#39;: address }, function(results, status) {
          if (status == google.maps.GeocoderStatus.OK &amp;&amp; results[0]) {
            console.log(&#39;Latitude: &#39; + results[0].geometry.location.lat());
            console.log(&#39;Longitude: &#39; + results[0].geometry.location.lng());

            lat = results[0].geometry.location.lat();
            lng = results[0].geometry.location.lng();

            // Now, retrieve the elevation
            elevationRequest = {&#39;locations&#39;: [results[0].geometry.location]}
            elevator.getElevationForLocations(elevationRequest, function(results, status) {
              if (status == google.maps.ElevationStatus.OK &amp;&amp; results[0]) {
                // Function that puts the geocoded intersection in memory
                insertData(streetY, streetX, lat, lng, results[0].elevation);
                console.log(&#39;Altitude: &#39; + results[0].elevation);
              } else {
                alert(&#34;Elevation service failure: &#34; + status);
              }
            });

          } else {
            console.log(&#34;Something went wrong when trying to geocode &#34; + streetX + &#39;,&#39; + streetY+ &#39;: &#39; + status);
          }
        });
      };
&lt;/pre&gt;
&lt;p&gt;Here&amp;rsquo;s the client-side batch, running for real:
&lt;img src=&#34;https://arnaudbrousseau.com/img/content/street-geocoding.png&#34; alt=&#34;Geocoder in action&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;compute-the-paths&#34;&gt;Compute the paths&lt;/h2&gt;
&lt;p&gt;Computing the paths is fairly easy once you have a structure like the one I
have. The hardest part was getting the colors right. And for that I used
&lt;a href=&#34;http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript&#34;&gt;http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Code to compute color for a given path:&lt;/p&gt;
&lt;pre class=&#34;brush: js&#34;&gt;
      var computeHexColor = function(start, end) {
        // Given two points, compute the color of the path
        // Red means super steep, green means flat

        var distance = Math.sqrt(Math.abs(start.lat - end.lat)*Math.abs(start.lat - end.lat) + Math.abs(start.lng - end.lng)*Math.abs(start.lng - end.lng));
        var elevation = Math.abs(start.alt - end.alt);
        var slope = elevation/distance;
        if (slope &gt; 16500) {
          /* Sanity check*/
          slope = 16500;
        }

        var normalizedSlope = slope/16500; // varies from 0 to 1. Woo!

        // Green is 1/3, 1, 0.5 in HSL
        // Red is 0, 1, 0.5
        // So we make the hue vary from 0 to 1/3. Nothing fancy.
        var rgbColor = this.hslToRgb(0.6*(1-normalizedSlope), 1, 0.5);
        var hexColor = &#39;#&#39; + this.rgbComponentTohex(rgbColor[0]) 
            + this.rgbComponentTohex(rgbColor[1]) 
            + this.rgbComponentTohex(rgbColor[2]);

        return hexColor;
      };
&lt;/pre&gt;
&lt;h2 id=&#34;result&#34;&gt;Result&lt;/h2&gt;
&lt;p&gt;After some amount of data cleaning (Google&amp;rsquo;s geocoder is sometimes not
accurate, see how sloppy Geary is!) the final result is available &lt;a href=&#34;https://arnaudbrousseau.com/labs/sf-hills/&#34;&gt;in the labs
section&lt;/a&gt;. It&amp;rsquo;s not over (I&amp;rsquo;m lazy and I have not finished
all parts of SF yet) but it gives you a pretty good idea of where hills are
when walking in the popular north eastern part of the city.&lt;/p&gt;
&lt;h2 id=&#34;further-reading&#34;&gt;Further reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Old article but really cool read (at least that&amp;rsquo;s what I thought): &lt;a href=&#34;http://www.datapointed.net/2009/11/the-steeps-of-san-francisco/&#34;&gt;http://www.datapointed.net/2009/11/the-steeps-of-san-francisco/&lt;/a&gt;&lt;br&gt;
The result visualization seems extremely accurate: &lt;a href=&#34;http://www.datapointed.net/visualizations/maps/san-francisco/streets-slope/&#34;&gt;http://www.datapointed.net/visualizations/maps/san-francisco/streets-slope/&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;http://hillmapper.com/&#34;&gt;Hillmapper&lt;/a&gt;: same idea but executed better. Props to Samuel Maurer (&lt;a href=&#34;https://twitter.com/smmaurer&#34;&gt;@smmaurer&lt;/a&gt;)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
  </channel>
</rss>
